mesa/st: merge st_renderbuffer into gl_renderbuffer.

This touches lots of places

Reviewed-by: Kristian H. Kristensen <hoegsberg@google.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/14675>
This commit is contained in:
Dave Airlie 2021-12-10 09:35:23 +10:00
parent 0b6caed85c
commit 527b6ca412
14 changed files with 295 additions and 340 deletions

View File

@ -1961,7 +1961,7 @@ dri2_interop_export_object(__DRIcontext *_ctx,
* "CL_OUT_OF_RESOURCES if there is a failure to allocate resources * "CL_OUT_OF_RESOURCES if there is a failure to allocate resources
* required by the OpenCL implementation on the device." * required by the OpenCL implementation on the device."
*/ */
res = st_renderbuffer(rb)->texture; res = rb->texture;
if (!res) { if (!res) {
simple_mtx_unlock(&ctx->Shared->Mutex); simple_mtx_unlock(&ctx->Shared->Mutex);
return MESA_GLINTEROP_OUT_OF_RESOURCES; return MESA_GLINTEROP_OUT_OF_RESOURCES;

View File

@ -2548,6 +2548,31 @@ struct gl_renderbuffer
struct gl_renderbuffer *rb, struct gl_renderbuffer *rb,
GLenum internalFormat, GLenum internalFormat,
GLuint width, GLuint height); GLuint width, GLuint height);
struct pipe_resource *texture;
/* This points to either "surface_linear" or "surface_srgb".
* It doesn't hold the pipe_surface reference. The other two do.
*/
struct pipe_surface *surface;
struct pipe_surface *surface_linear;
struct pipe_surface *surface_srgb;
GLboolean defined; /**< defined contents? */
struct pipe_transfer *transfer; /**< only used when mapping the resource */
/**
* Used only when hardware accumulation buffers are not supported.
*/
boolean software;
void *data;
bool use_readpix_cache;
/* Inputs from Driver.RenderTexture, don't use directly. */
boolean is_rtt; /**< whether Driver.RenderTexture was called */
unsigned rtt_face, rtt_slice;
boolean rtt_layered; /**< whether glFramebufferTexture was called */
unsigned rtt_nr_samples; /**< from FramebufferTexture2DMultisampleEXT */
}; };

View File

@ -111,7 +111,7 @@ st_update_framebuffer_state( struct st_context *st )
{ {
struct pipe_framebuffer_state framebuffer; struct pipe_framebuffer_state framebuffer;
struct gl_framebuffer *fb = st->ctx->DrawBuffer; struct gl_framebuffer *fb = st->ctx->DrawBuffer;
struct st_renderbuffer *strb; struct gl_renderbuffer *rb;
GLuint i; GLuint i;
st_flush_bitmap_cache(st); st_flush_bitmap_cache(st);
@ -142,23 +142,23 @@ st_update_framebuffer_state( struct st_context *st )
for (i = 0; i < fb->_NumColorDrawBuffers; i++) { for (i = 0; i < fb->_NumColorDrawBuffers; i++) {
framebuffer.cbufs[i] = NULL; framebuffer.cbufs[i] = NULL;
strb = st_renderbuffer(fb->_ColorDrawBuffers[i]); rb = fb->_ColorDrawBuffers[i];
if (strb) { if (rb) {
if (strb->is_rtt || (strb->texture && if (rb->is_rtt || (rb->texture &&
_mesa_is_format_srgb(strb->Base.Format))) { _mesa_is_format_srgb(rb->Format))) {
/* rendering to a GL texture, may have to update surface */ /* rendering to a GL texture, may have to update surface */
st_update_renderbuffer_surface(st, strb); st_update_renderbuffer_surface(st, rb);
} }
if (strb->surface) { if (rb->surface) {
if (strb->surface->context != st->pipe) { if (rb->surface->context != st->pipe) {
st_regen_renderbuffer_surface(st, strb); st_regen_renderbuffer_surface(st, rb);
} }
framebuffer.cbufs[i] = strb->surface; framebuffer.cbufs[i] = rb->surface;
update_framebuffer_size(&framebuffer, strb->surface); update_framebuffer_size(&framebuffer, rb->surface);
} }
strb->defined = GL_TRUE; /* we'll be drawing something */ rb->defined = GL_TRUE; /* we'll be drawing something */
} }
} }
@ -175,21 +175,21 @@ st_update_framebuffer_state( struct st_context *st )
/* /*
* Depth/Stencil renderbuffer/surface. * Depth/Stencil renderbuffer/surface.
*/ */
strb = st_renderbuffer(fb->Attachment[BUFFER_DEPTH].Renderbuffer); rb = fb->Attachment[BUFFER_DEPTH].Renderbuffer;
if (!strb) if (!rb)
strb = st_renderbuffer(fb->Attachment[BUFFER_STENCIL].Renderbuffer); rb = fb->Attachment[BUFFER_STENCIL].Renderbuffer;
if (strb) { if (rb) {
if (strb->is_rtt) { if (rb->is_rtt) {
/* rendering to a GL texture, may have to update surface */ /* rendering to a GL texture, may have to update surface */
st_update_renderbuffer_surface(st, strb); st_update_renderbuffer_surface(st, rb);
} }
if (strb->surface && strb->surface->context != st->pipe) { if (rb->surface && rb->surface->context != st->pipe) {
st_regen_renderbuffer_surface(st, strb); st_regen_renderbuffer_surface(st, rb);
} }
framebuffer.zsbuf = strb->surface; framebuffer.zsbuf = rb->surface;
if (strb->surface) if (rb->surface)
update_framebuffer_size(&framebuffer, strb->surface); update_framebuffer_size(&framebuffer, rb->surface);
} }
else else
framebuffer.zsbuf = NULL; framebuffer.zsbuf = NULL;

View File

@ -202,8 +202,7 @@ st_BlitFramebuffer(struct gl_context *ctx,
blit.src.format = util_format_linear(blit.src.format); blit.src.format = util_format_linear(blit.src.format);
} }
else { else {
struct st_renderbuffer *srcRb = struct gl_renderbuffer *srcRb = readFB->_ColorReadBuffer;
st_renderbuffer(readFB->_ColorReadBuffer);
struct pipe_surface *srcSurf; struct pipe_surface *srcSurf;
if (!srcRb) if (!srcRb)
@ -223,8 +222,7 @@ st_BlitFramebuffer(struct gl_context *ctx,
} }
for (i = 0; i < drawFB->_NumColorDrawBuffers; i++) { for (i = 0; i < drawFB->_NumColorDrawBuffers; i++) {
struct st_renderbuffer *dstRb = struct gl_renderbuffer *dstRb = drawFB->_ColorDrawBuffers[i];
st_renderbuffer(drawFB->_ColorDrawBuffers[i]);
if (dstRb) { if (dstRb) {
struct pipe_surface *dstSurf; struct pipe_surface *dstSurf;
@ -250,17 +248,17 @@ st_BlitFramebuffer(struct gl_context *ctx,
/* depth and/or stencil blit */ /* depth and/or stencil blit */
/* get src/dst depth surfaces */ /* get src/dst depth surfaces */
struct st_renderbuffer *srcDepthRb = struct gl_renderbuffer *srcDepthRb =
st_renderbuffer(readFB->Attachment[BUFFER_DEPTH].Renderbuffer); readFB->Attachment[BUFFER_DEPTH].Renderbuffer;
struct st_renderbuffer *dstDepthRb = struct gl_renderbuffer *dstDepthRb =
st_renderbuffer(drawFB->Attachment[BUFFER_DEPTH].Renderbuffer); drawFB->Attachment[BUFFER_DEPTH].Renderbuffer;
struct pipe_surface *dstDepthSurf = struct pipe_surface *dstDepthSurf =
dstDepthRb ? dstDepthRb->surface : NULL; dstDepthRb ? dstDepthRb->surface : NULL;
struct st_renderbuffer *srcStencilRb = struct gl_renderbuffer *srcStencilRb =
st_renderbuffer(readFB->Attachment[BUFFER_STENCIL].Renderbuffer); readFB->Attachment[BUFFER_STENCIL].Renderbuffer;
struct st_renderbuffer *dstStencilRb = struct gl_renderbuffer *dstStencilRb =
st_renderbuffer(drawFB->Attachment[BUFFER_STENCIL].Renderbuffer); drawFB->Attachment[BUFFER_STENCIL].Renderbuffer;
struct pipe_surface *dstStencilSurf = struct pipe_surface *dstStencilSurf =
dstStencilRb ? dstStencilRb->surface : NULL; dstStencilRb ? dstStencilRb->surface : NULL;

View File

@ -445,10 +445,9 @@ st_Clear(struct gl_context *ctx, GLbitfield mask)
if (b != BUFFER_NONE && mask & (1 << b)) { if (b != BUFFER_NONE && mask & (1 << b)) {
struct gl_renderbuffer *rb struct gl_renderbuffer *rb
= ctx->DrawBuffer->Attachment[b].Renderbuffer; = ctx->DrawBuffer->Attachment[b].Renderbuffer;
struct st_renderbuffer *strb = st_renderbuffer(rb);
int colormask_index = ctx->Extensions.EXT_draw_buffers2 ? i : 0; int colormask_index = ctx->Extensions.EXT_draw_buffers2 ? i : 0;
if (!strb || !strb->surface) if (!rb || !rb->surface)
continue; continue;
unsigned colormask = unsigned colormask =
@ -458,7 +457,7 @@ st_Clear(struct gl_context *ctx, GLbitfield mask)
continue; continue;
unsigned surf_colormask = unsigned surf_colormask =
util_format_colormask(util_format_description(strb->surface->format)); util_format_colormask(util_format_description(rb->surface->format));
bool scissor = is_scissor_enabled(ctx, rb); bool scissor = is_scissor_enabled(ctx, rb);
if ((scissor && !st->can_scissor_clear) || if ((scissor && !st->can_scissor_clear) ||
@ -473,9 +472,7 @@ st_Clear(struct gl_context *ctx, GLbitfield mask)
} }
if (mask & BUFFER_BIT_DEPTH) { if (mask & BUFFER_BIT_DEPTH) {
struct st_renderbuffer *strb = st_renderbuffer(depthRb); if (depthRb->surface && ctx->Depth.Mask) {
if (strb->surface && ctx->Depth.Mask) {
bool scissor = is_scissor_enabled(ctx, depthRb); bool scissor = is_scissor_enabled(ctx, depthRb);
if ((scissor && !st->can_scissor_clear) || if ((scissor && !st->can_scissor_clear) ||
is_window_rectangle_enabled(ctx)) is_window_rectangle_enabled(ctx))
@ -486,9 +483,7 @@ st_Clear(struct gl_context *ctx, GLbitfield mask)
} }
} }
if (mask & BUFFER_BIT_STENCIL) { if (mask & BUFFER_BIT_STENCIL) {
struct st_renderbuffer *strb = st_renderbuffer(stencilRb); if (stencilRb->surface && !is_stencil_disabled(ctx, stencilRb)) {
if (strb->surface && !is_stencil_disabled(ctx, stencilRb)) {
bool scissor = is_scissor_enabled(ctx, stencilRb); bool scissor = is_scissor_enabled(ctx, stencilRb);
if ((scissor && !st->can_scissor_clear) || if ((scissor && !st->can_scissor_clear) ||
is_window_rectangle_enabled(ctx) || is_window_rectangle_enabled(ctx) ||

View File

@ -655,8 +655,7 @@ st_CopyImageSubData(struct gl_context *ctx,
src_z += src_image->TexObject->Attrib.MinLayer; src_z += src_image->TexObject->Attrib.MinLayer;
} }
} else { } else {
struct st_renderbuffer *src = st_renderbuffer(src_renderbuffer); src_res = src_renderbuffer->texture;
src_res = src->texture;
src_level = 0; src_level = 0;
} }
@ -671,8 +670,7 @@ st_CopyImageSubData(struct gl_context *ctx,
dst_z += dst_image->TexObject->Attrib.MinLayer; dst_z += dst_image->TexObject->Attrib.MinLayer;
} }
} else { } else {
struct st_renderbuffer *dst = st_renderbuffer(dst_renderbuffer); dst_res = dst_renderbuffer->texture;
dst_res = dst->texture;
dst_level = 0; dst_level = 0;
} }

View File

@ -964,7 +964,7 @@ draw_stencil_pixels(struct gl_context *ctx, GLint x, GLint y,
{ {
struct st_context *st = st_context(ctx); struct st_context *st = st_context(ctx);
struct pipe_context *pipe = st->pipe; struct pipe_context *pipe = st->pipe;
struct st_renderbuffer *strb; struct gl_renderbuffer *rb;
enum pipe_map_flags usage; enum pipe_map_flags usage;
struct pipe_transfer *pt; struct pipe_transfer *pt;
const GLboolean zoom = ctx->Pixel.ZoomX != 1.0 || ctx->Pixel.ZoomY != 1.0; const GLboolean zoom = ctx->Pixel.ZoomX != 1.0 || ctx->Pixel.ZoomY != 1.0;
@ -973,15 +973,14 @@ draw_stencil_pixels(struct gl_context *ctx, GLint x, GLint y,
GLubyte *sValues; GLubyte *sValues;
GLuint *zValues; GLuint *zValues;
strb = st_renderbuffer(ctx->DrawBuffer-> rb = ctx->DrawBuffer->Attachment[BUFFER_STENCIL].Renderbuffer;
Attachment[BUFFER_STENCIL].Renderbuffer);
if (st_fb_orientation(ctx->DrawBuffer) == Y_0_TOP) { if (st_fb_orientation(ctx->DrawBuffer) == Y_0_TOP) {
y = ctx->DrawBuffer->Height - y - height; y = ctx->DrawBuffer->Height - y - height;
} }
if (format == GL_STENCIL_INDEX && if (format == GL_STENCIL_INDEX &&
_mesa_is_format_packed_depth_stencil(strb->Base.Format)) { _mesa_is_format_packed_depth_stencil(rb->Format)) {
/* writing stencil to a combined depth+stencil buffer */ /* writing stencil to a combined depth+stencil buffer */
usage = PIPE_MAP_READ_WRITE; usage = PIPE_MAP_READ_WRITE;
} }
@ -989,9 +988,9 @@ draw_stencil_pixels(struct gl_context *ctx, GLint x, GLint y,
usage = PIPE_MAP_WRITE; usage = PIPE_MAP_WRITE;
} }
stmap = pipe_texture_map(pipe, strb->texture, stmap = pipe_texture_map(pipe, rb->texture,
strb->surface->u.tex.level, rb->surface->u.tex.level,
strb->surface->u.tex.first_layer, rb->surface->u.tex.first_layer,
usage, x, y, usage, x, y,
width, height, &pt); width, height, &pt);
@ -1418,7 +1417,7 @@ copy_stencil_pixels(struct gl_context *ctx, GLint srcx, GLint srcy,
GLsizei width, GLsizei height, GLsizei width, GLsizei height,
GLint dstx, GLint dsty) GLint dstx, GLint dsty)
{ {
struct st_renderbuffer *rbDraw; struct gl_renderbuffer *rbDraw;
struct pipe_context *pipe = st_context(ctx)->pipe; struct pipe_context *pipe = st_context(ctx)->pipe;
enum pipe_map_flags usage; enum pipe_map_flags usage;
struct pipe_transfer *ptDraw; struct pipe_transfer *ptDraw;
@ -1433,8 +1432,7 @@ copy_stencil_pixels(struct gl_context *ctx, GLint srcx, GLint srcy,
} }
/* Get the dest renderbuffer */ /* Get the dest renderbuffer */
rbDraw = st_renderbuffer(ctx->DrawBuffer-> rbDraw = ctx->DrawBuffer->Attachment[BUFFER_STENCIL].Renderbuffer;
Attachment[BUFFER_STENCIL].Renderbuffer);
/* this will do stencil pixel transfer ops */ /* this will do stencil pixel transfer ops */
_mesa_readpixels(ctx, srcx, srcy, width, height, _mesa_readpixels(ctx, srcx, srcy, width, height,
@ -1453,13 +1451,13 @@ copy_stencil_pixels(struct gl_context *ctx, GLint srcx, GLint srcy,
} }
} }
if (_mesa_is_format_packed_depth_stencil(rbDraw->Base.Format)) if (_mesa_is_format_packed_depth_stencil(rbDraw->Format))
usage = PIPE_MAP_READ_WRITE; usage = PIPE_MAP_READ_WRITE;
else else
usage = PIPE_MAP_WRITE; usage = PIPE_MAP_WRITE;
if (st_fb_orientation(ctx->DrawBuffer) == Y_0_TOP) { if (st_fb_orientation(ctx->DrawBuffer) == Y_0_TOP) {
dsty = rbDraw->Base.Height - dsty - height; dsty = rbDraw->Height - dsty - height;
} }
assert(util_format_get_blockwidth(rbDraw->texture->format) == 1); assert(util_format_get_blockwidth(rbDraw->texture->format) == 1);
@ -1489,7 +1487,7 @@ copy_stencil_pixels(struct gl_context *ctx, GLint srcx, GLint srcy,
dst = drawMap + y * ptDraw->stride; dst = drawMap + y * ptDraw->stride;
src = buffer + i * width; src = buffer + i * width;
_mesa_pack_ubyte_stencil_row(rbDraw->Base.Format, width, src, dst); _mesa_pack_ubyte_stencil_row(rbDraw->Format, width, src, dst);
} }
free(buffer); free(buffer);
@ -1502,14 +1500,11 @@ copy_stencil_pixels(struct gl_context *ctx, GLint srcx, GLint srcy,
/** /**
* Return renderbuffer to use for reading color pixels for glCopyPixels * Return renderbuffer to use for reading color pixels for glCopyPixels
*/ */
static struct st_renderbuffer * static struct gl_renderbuffer *
st_get_color_read_renderbuffer(struct gl_context *ctx) st_get_color_read_renderbuffer(struct gl_context *ctx)
{ {
struct gl_framebuffer *fb = ctx->ReadBuffer; struct gl_framebuffer *fb = ctx->ReadBuffer;
struct st_renderbuffer *strb = return fb->_ColorReadBuffer;
st_renderbuffer(fb->_ColorReadBuffer);
return strb;
} }
@ -1554,7 +1549,7 @@ blit_copy_pixels(struct gl_context *ctx, GLint srcx, GLint srcy,
!_mesa_ati_fragment_shader_enabled(ctx) && !_mesa_ati_fragment_shader_enabled(ctx) &&
ctx->DrawBuffer->_NumColorDrawBuffers == 1)) && ctx->DrawBuffer->_NumColorDrawBuffers == 1)) &&
!ctx->Query.CurrentOcclusionObject) { !ctx->Query.CurrentOcclusionObject) {
struct st_renderbuffer *rbRead, *rbDraw; struct gl_renderbuffer *rbRead, *rbDraw;
/* /*
* Clip the read region against the src buffer bounds. * Clip the read region against the src buffer bounds.
@ -1586,20 +1581,20 @@ blit_copy_pixels(struct gl_context *ctx, GLint srcx, GLint srcy,
if (type == GL_COLOR) { if (type == GL_COLOR) {
rbRead = st_get_color_read_renderbuffer(ctx); rbRead = st_get_color_read_renderbuffer(ctx);
rbDraw = st_renderbuffer(ctx->DrawBuffer->_ColorDrawBuffers[0]); rbDraw = ctx->DrawBuffer->_ColorDrawBuffers[0];
} else if (type == GL_DEPTH || type == GL_DEPTH_STENCIL) { } else if (type == GL_DEPTH || type == GL_DEPTH_STENCIL) {
rbRead = st_renderbuffer(ctx->ReadBuffer->Attachment[BUFFER_DEPTH].Renderbuffer); rbRead = ctx->ReadBuffer->Attachment[BUFFER_DEPTH].Renderbuffer;
rbDraw = st_renderbuffer(ctx->DrawBuffer->Attachment[BUFFER_DEPTH].Renderbuffer); rbDraw = ctx->DrawBuffer->Attachment[BUFFER_DEPTH].Renderbuffer;
} else if (type == GL_STENCIL) { } else if (type == GL_STENCIL) {
rbRead = st_renderbuffer(ctx->ReadBuffer->Attachment[BUFFER_STENCIL].Renderbuffer); rbRead = ctx->ReadBuffer->Attachment[BUFFER_STENCIL].Renderbuffer;
rbDraw = st_renderbuffer(ctx->DrawBuffer->Attachment[BUFFER_STENCIL].Renderbuffer); rbDraw = ctx->DrawBuffer->Attachment[BUFFER_STENCIL].Renderbuffer;
} else { } else {
return false; return false;
} }
/* Flip src/dst position depending on the orientation of buffers. */ /* Flip src/dst position depending on the orientation of buffers. */
if (st_fb_orientation(ctx->ReadBuffer) == Y_0_TOP) { if (st_fb_orientation(ctx->ReadBuffer) == Y_0_TOP) {
readY = rbRead->Base.Height - readY; readY = rbRead->Height - readY;
readH = -readH; readH = -readH;
} }
@ -1607,7 +1602,7 @@ blit_copy_pixels(struct gl_context *ctx, GLint srcx, GLint srcy,
/* We can't flip the destination for pipe->blit, so we only adjust /* We can't flip the destination for pipe->blit, so we only adjust
* its position and flip the source. * its position and flip the source.
*/ */
drawY = rbDraw->Base.Height - drawY - drawH; drawY = rbDraw->Height - drawY - drawH;
readY += readH; readY += readH;
readH = -readH; readH = -readH;
} }
@ -1678,7 +1673,7 @@ st_CopyPixels(struct gl_context *ctx, GLint srcx, GLint srcy,
struct st_context *st = st_context(ctx); struct st_context *st = st_context(ctx);
struct pipe_context *pipe = st->pipe; struct pipe_context *pipe = st->pipe;
struct pipe_screen *screen = st->screen; struct pipe_screen *screen = st->screen;
struct st_renderbuffer *rbRead; struct gl_renderbuffer *rbRead;
void *driver_fp; void *driver_fp;
struct pipe_resource *pt; struct pipe_resource *pt;
struct pipe_sampler_view *sv[2] = { NULL }; struct pipe_sampler_view *sv[2] = { NULL };
@ -1747,21 +1742,17 @@ st_CopyPixels(struct gl_context *ctx, GLint srcx, GLint srcy,
*/ */
st_upload_constants(st, &st->fp->Base, MESA_SHADER_FRAGMENT); st_upload_constants(st, &st->fp->Base, MESA_SHADER_FRAGMENT);
} else if (type == GL_DEPTH) { } else if (type == GL_DEPTH) {
rbRead = st_renderbuffer(ctx->ReadBuffer-> rbRead = ctx->ReadBuffer->Attachment[BUFFER_DEPTH].Renderbuffer;
Attachment[BUFFER_DEPTH].Renderbuffer);
driver_fp = get_drawpix_z_stencil_program(st, GL_TRUE, GL_FALSE); driver_fp = get_drawpix_z_stencil_program(st, GL_TRUE, GL_FALSE);
} else if (type == GL_STENCIL) { } else if (type == GL_STENCIL) {
rbRead = st_renderbuffer(ctx->ReadBuffer-> rbRead = ctx->ReadBuffer->Attachment[BUFFER_STENCIL].Renderbuffer;
Attachment[BUFFER_STENCIL].Renderbuffer);
driver_fp = get_drawpix_z_stencil_program(st, GL_FALSE, GL_TRUE); driver_fp = get_drawpix_z_stencil_program(st, GL_FALSE, GL_TRUE);
} else if (type == GL_DEPTH_STENCIL) { } else if (type == GL_DEPTH_STENCIL) {
rbRead = st_renderbuffer(ctx->ReadBuffer-> rbRead = ctx->ReadBuffer->Attachment[BUFFER_DEPTH].Renderbuffer;
Attachment[BUFFER_DEPTH].Renderbuffer);
driver_fp = get_drawpix_z_stencil_program(st, GL_TRUE, GL_TRUE); driver_fp = get_drawpix_z_stencil_program(st, GL_TRUE, GL_TRUE);
} else { } else {
assert(type == GL_DEPTH_STENCIL_TO_RGBA_NV || type == GL_DEPTH_STENCIL_TO_BGRA_NV); assert(type == GL_DEPTH_STENCIL_TO_RGBA_NV || type == GL_DEPTH_STENCIL_TO_BGRA_NV);
rbRead = st_renderbuffer(ctx->ReadBuffer-> rbRead = ctx->ReadBuffer->Attachment[BUFFER_DEPTH].Renderbuffer;
Attachment[BUFFER_DEPTH].Renderbuffer);
if (type == GL_DEPTH_STENCIL_TO_RGBA_NV) if (type == GL_DEPTH_STENCIL_TO_RGBA_NV)
driver_fp = get_drawpix_zs_to_color_program(st, GL_TRUE); driver_fp = get_drawpix_zs_to_color_program(st, GL_TRUE);
else else

View File

@ -231,7 +231,6 @@ st_egl_image_target_renderbuffer_storage(struct gl_context *ctx,
struct gl_renderbuffer *rb, struct gl_renderbuffer *rb,
GLeglImageOES image_handle) GLeglImageOES image_handle)
{ {
struct st_renderbuffer *strb = st_renderbuffer(rb);
struct st_egl_image stimg; struct st_egl_image stimg;
bool native_supported; bool native_supported;
@ -252,11 +251,11 @@ st_egl_image_target_renderbuffer_storage(struct gl_context *ctx,
if (!ps) if (!ps)
return; return;
strb->Base.Format = st_pipe_format_to_mesa_format(ps->format); rb->Format = st_pipe_format_to_mesa_format(ps->format);
strb->Base._BaseFormat = st_pipe_format_to_base_format(ps->format); rb->_BaseFormat = st_pipe_format_to_base_format(ps->format);
strb->Base.InternalFormat = strb->Base._BaseFormat; rb->InternalFormat = rb->_BaseFormat;
st_set_ws_renderbuffer_surface(strb, ps); st_set_ws_renderbuffer_surface(rb, ps);
pipe_surface_reference(&ps, NULL); pipe_surface_reference(&ps, NULL);
} }
} }

View File

@ -68,12 +68,11 @@ st_renderbuffer_alloc_sw_storage(struct gl_context * ctx,
GLuint width, GLuint height) GLuint width, GLuint height)
{ {
struct st_context *st = st_context(ctx); struct st_context *st = st_context(ctx);
struct st_renderbuffer *strb = st_renderbuffer(rb);
enum pipe_format format; enum pipe_format format;
size_t size; size_t size;
free(strb->data); free(rb->data);
strb->data = NULL; rb->data = NULL;
if (internalFormat == GL_RGBA16_SNORM) { if (internalFormat == GL_RGBA16_SNORM) {
/* Special case for software accum buffers. Otherwise, if the /* Special case for software accum buffers. Otherwise, if the
@ -94,11 +93,11 @@ st_renderbuffer_alloc_sw_storage(struct gl_context * ctx,
} }
} }
strb->Base.Format = st_pipe_format_to_mesa_format(format); rb->Format = st_pipe_format_to_mesa_format(format);
size = _mesa_format_image_size(strb->Base.Format, width, height, 1); size = _mesa_format_image_size(rb->Format, width, height, 1);
strb->data = malloc(size); rb->data = malloc(size);
return strb->data != NULL; return rb->data != NULL;
} }
@ -115,27 +114,26 @@ st_renderbuffer_alloc_storage(struct gl_context * ctx,
{ {
struct st_context *st = st_context(ctx); struct st_context *st = st_context(ctx);
struct pipe_screen *screen = st->screen; struct pipe_screen *screen = st->screen;
struct st_renderbuffer *strb = st_renderbuffer(rb);
enum pipe_format format = PIPE_FORMAT_NONE; enum pipe_format format = PIPE_FORMAT_NONE;
struct pipe_resource templ; struct pipe_resource templ;
/* init renderbuffer fields */ /* init renderbuffer fields */
strb->Base.Width = width; rb->Width = width;
strb->Base.Height = height; rb->Height = height;
strb->Base._BaseFormat = _mesa_base_fbo_format(ctx, internalFormat); rb->_BaseFormat = _mesa_base_fbo_format(ctx, internalFormat);
strb->defined = GL_FALSE; /* undefined contents now */ rb->defined = GL_FALSE; /* undefined contents now */
if (strb->software) { if (rb->software) {
return st_renderbuffer_alloc_sw_storage(ctx, rb, internalFormat, return st_renderbuffer_alloc_sw_storage(ctx, rb, internalFormat,
width, height); width, height);
} }
/* Free the old surface and texture /* Free the old surface and texture
*/ */
pipe_surface_reference(&strb->surface_srgb, NULL); pipe_surface_reference(&rb->surface_srgb, NULL);
pipe_surface_reference(&strb->surface_linear, NULL); pipe_surface_reference(&rb->surface_linear, NULL);
strb->surface = NULL; rb->surface = NULL;
pipe_resource_reference(&strb->texture, NULL); pipe_resource_reference(&rb->texture, NULL);
/* If an sRGB framebuffer is unsupported, sRGB formats behave like linear /* If an sRGB framebuffer is unsupported, sRGB formats behave like linear
* formats. * formats.
@ -233,7 +231,7 @@ st_renderbuffer_alloc_storage(struct gl_context * ctx,
return GL_TRUE; return GL_TRUE;
} }
strb->Base.Format = st_pipe_format_to_mesa_format(format); rb->Format = st_pipe_format_to_mesa_format(format);
if (width == 0 || height == 0) { if (width == 0 || height == 0) {
/* if size is zero, nothing to allocate */ /* if size is zero, nothing to allocate */
@ -255,7 +253,7 @@ st_renderbuffer_alloc_storage(struct gl_context * ctx,
if (util_format_is_depth_or_stencil(format)) { if (util_format_is_depth_or_stencil(format)) {
templ.bind = PIPE_BIND_DEPTH_STENCIL; templ.bind = PIPE_BIND_DEPTH_STENCIL;
} }
else if (strb->Base.Name != 0) { else if (rb->Name != 0) {
/* this is a user-created renderbuffer */ /* this is a user-created renderbuffer */
templ.bind = PIPE_BIND_RENDER_TARGET; templ.bind = PIPE_BIND_RENDER_TARGET;
} }
@ -265,13 +263,13 @@ st_renderbuffer_alloc_storage(struct gl_context * ctx,
PIPE_BIND_RENDER_TARGET); PIPE_BIND_RENDER_TARGET);
} }
strb->texture = screen->resource_create(screen, &templ); rb->texture = screen->resource_create(screen, &templ);
if (!strb->texture) if (!rb->texture)
return FALSE; return FALSE;
st_update_renderbuffer_surface(st, strb); st_update_renderbuffer_surface(st, rb);
return strb->surface != NULL; return rb->surface != NULL;
} }
@ -281,18 +279,17 @@ st_renderbuffer_alloc_storage(struct gl_context * ctx,
static void static void
st_renderbuffer_delete(struct gl_context *ctx, struct gl_renderbuffer *rb) st_renderbuffer_delete(struct gl_context *ctx, struct gl_renderbuffer *rb)
{ {
struct st_renderbuffer *strb = st_renderbuffer(rb);
if (ctx) { if (ctx) {
struct st_context *st = st_context(ctx); struct st_context *st = st_context(ctx);
pipe_surface_release(st->pipe, &strb->surface_srgb); pipe_surface_release(st->pipe, &rb->surface_srgb);
pipe_surface_release(st->pipe, &strb->surface_linear); pipe_surface_release(st->pipe, &rb->surface_linear);
} else { } else {
pipe_surface_release_no_context(&strb->surface_srgb); pipe_surface_release_no_context(&rb->surface_srgb);
pipe_surface_release_no_context(&strb->surface_linear); pipe_surface_release_no_context(&rb->surface_linear);
} }
strb->surface = NULL; rb->surface = NULL;
pipe_resource_reference(&strb->texture, NULL); pipe_resource_reference(&rb->texture, NULL);
free(strb->data); free(rb->data);
_mesa_delete_renderbuffer(ctx, rb); _mesa_delete_renderbuffer(ctx, rb);
} }
@ -303,13 +300,13 @@ st_renderbuffer_delete(struct gl_context *ctx, struct gl_renderbuffer *rb)
struct gl_renderbuffer * struct gl_renderbuffer *
st_new_renderbuffer(struct gl_context *ctx, GLuint name) st_new_renderbuffer(struct gl_context *ctx, GLuint name)
{ {
struct st_renderbuffer *strb = CALLOC_STRUCT(st_renderbuffer); struct gl_renderbuffer *rb = CALLOC_STRUCT(gl_renderbuffer);
if (strb) { if (rb) {
assert(name != 0); assert(name != 0);
_mesa_init_renderbuffer(&strb->Base, name); _mesa_init_renderbuffer(rb, name);
strb->Base.Delete = st_renderbuffer_delete; rb->Delete = st_renderbuffer_delete;
strb->Base.AllocStorage = st_renderbuffer_alloc_storage; rb->AllocStorage = st_renderbuffer_alloc_storage;
return &strb->Base; return rb;
} }
return NULL; return NULL;
} }
@ -322,146 +319,146 @@ st_new_renderbuffer(struct gl_context *ctx, GLuint name)
struct gl_renderbuffer * struct gl_renderbuffer *
st_new_renderbuffer_fb(enum pipe_format format, unsigned samples, boolean sw) st_new_renderbuffer_fb(enum pipe_format format, unsigned samples, boolean sw)
{ {
struct st_renderbuffer *strb; struct gl_renderbuffer *rb;
strb = CALLOC_STRUCT(st_renderbuffer); rb = CALLOC_STRUCT(gl_renderbuffer);
if (!strb) { if (!rb) {
_mesa_error(NULL, GL_OUT_OF_MEMORY, "creating renderbuffer"); _mesa_error(NULL, GL_OUT_OF_MEMORY, "creating renderbuffer");
return NULL; return NULL;
} }
_mesa_init_renderbuffer(&strb->Base, 0); _mesa_init_renderbuffer(rb, 0);
strb->Base.ClassID = 0x4242; /* just a unique value */ rb->ClassID = 0x4242; /* just a unique value */
strb->Base.NumSamples = samples; rb->NumSamples = samples;
strb->Base.NumStorageSamples = samples; rb->NumStorageSamples = samples;
strb->Base.Format = st_pipe_format_to_mesa_format(format); rb->Format = st_pipe_format_to_mesa_format(format);
strb->Base._BaseFormat = _mesa_get_format_base_format(strb->Base.Format); rb->_BaseFormat = _mesa_get_format_base_format(rb->Format);
strb->software = sw; rb->software = sw;
switch (format) { switch (format) {
case PIPE_FORMAT_B10G10R10A2_UNORM: case PIPE_FORMAT_B10G10R10A2_UNORM:
case PIPE_FORMAT_R10G10B10A2_UNORM: case PIPE_FORMAT_R10G10B10A2_UNORM:
strb->Base.InternalFormat = GL_RGB10_A2; rb->InternalFormat = GL_RGB10_A2;
break; break;
case PIPE_FORMAT_R10G10B10X2_UNORM: case PIPE_FORMAT_R10G10B10X2_UNORM:
case PIPE_FORMAT_B10G10R10X2_UNORM: case PIPE_FORMAT_B10G10R10X2_UNORM:
strb->Base.InternalFormat = GL_RGB10; rb->InternalFormat = GL_RGB10;
break; break;
case PIPE_FORMAT_R8G8B8A8_UNORM: case PIPE_FORMAT_R8G8B8A8_UNORM:
case PIPE_FORMAT_B8G8R8A8_UNORM: case PIPE_FORMAT_B8G8R8A8_UNORM:
case PIPE_FORMAT_A8R8G8B8_UNORM: case PIPE_FORMAT_A8R8G8B8_UNORM:
strb->Base.InternalFormat = GL_RGBA8; rb->InternalFormat = GL_RGBA8;
break; break;
case PIPE_FORMAT_R8G8B8X8_UNORM: case PIPE_FORMAT_R8G8B8X8_UNORM:
case PIPE_FORMAT_B8G8R8X8_UNORM: case PIPE_FORMAT_B8G8R8X8_UNORM:
case PIPE_FORMAT_X8R8G8B8_UNORM: case PIPE_FORMAT_X8R8G8B8_UNORM:
case PIPE_FORMAT_R8G8B8_UNORM: case PIPE_FORMAT_R8G8B8_UNORM:
strb->Base.InternalFormat = GL_RGB8; rb->InternalFormat = GL_RGB8;
break; break;
case PIPE_FORMAT_R8G8B8A8_SRGB: case PIPE_FORMAT_R8G8B8A8_SRGB:
case PIPE_FORMAT_B8G8R8A8_SRGB: case PIPE_FORMAT_B8G8R8A8_SRGB:
case PIPE_FORMAT_A8R8G8B8_SRGB: case PIPE_FORMAT_A8R8G8B8_SRGB:
strb->Base.InternalFormat = GL_SRGB8_ALPHA8; rb->InternalFormat = GL_SRGB8_ALPHA8;
break; break;
case PIPE_FORMAT_R8G8B8X8_SRGB: case PIPE_FORMAT_R8G8B8X8_SRGB:
case PIPE_FORMAT_B8G8R8X8_SRGB: case PIPE_FORMAT_B8G8R8X8_SRGB:
case PIPE_FORMAT_X8R8G8B8_SRGB: case PIPE_FORMAT_X8R8G8B8_SRGB:
strb->Base.InternalFormat = GL_SRGB8; rb->InternalFormat = GL_SRGB8;
break; break;
case PIPE_FORMAT_B5G5R5A1_UNORM: case PIPE_FORMAT_B5G5R5A1_UNORM:
strb->Base.InternalFormat = GL_RGB5_A1; rb->InternalFormat = GL_RGB5_A1;
break; break;
case PIPE_FORMAT_B4G4R4A4_UNORM: case PIPE_FORMAT_B4G4R4A4_UNORM:
strb->Base.InternalFormat = GL_RGBA4; rb->InternalFormat = GL_RGBA4;
break; break;
case PIPE_FORMAT_B5G6R5_UNORM: case PIPE_FORMAT_B5G6R5_UNORM:
strb->Base.InternalFormat = GL_RGB565; rb->InternalFormat = GL_RGB565;
break; break;
case PIPE_FORMAT_Z16_UNORM: case PIPE_FORMAT_Z16_UNORM:
strb->Base.InternalFormat = GL_DEPTH_COMPONENT16; rb->InternalFormat = GL_DEPTH_COMPONENT16;
break; break;
case PIPE_FORMAT_Z32_UNORM: case PIPE_FORMAT_Z32_UNORM:
strb->Base.InternalFormat = GL_DEPTH_COMPONENT32; rb->InternalFormat = GL_DEPTH_COMPONENT32;
break; break;
case PIPE_FORMAT_Z24_UNORM_S8_UINT: case PIPE_FORMAT_Z24_UNORM_S8_UINT:
case PIPE_FORMAT_S8_UINT_Z24_UNORM: case PIPE_FORMAT_S8_UINT_Z24_UNORM:
strb->Base.InternalFormat = GL_DEPTH24_STENCIL8_EXT; rb->InternalFormat = GL_DEPTH24_STENCIL8_EXT;
break; break;
case PIPE_FORMAT_Z24X8_UNORM: case PIPE_FORMAT_Z24X8_UNORM:
case PIPE_FORMAT_X8Z24_UNORM: case PIPE_FORMAT_X8Z24_UNORM:
strb->Base.InternalFormat = GL_DEPTH_COMPONENT24; rb->InternalFormat = GL_DEPTH_COMPONENT24;
break; break;
case PIPE_FORMAT_S8_UINT: case PIPE_FORMAT_S8_UINT:
strb->Base.InternalFormat = GL_STENCIL_INDEX8_EXT; rb->InternalFormat = GL_STENCIL_INDEX8_EXT;
break; break;
case PIPE_FORMAT_R16G16B16A16_SNORM: case PIPE_FORMAT_R16G16B16A16_SNORM:
/* accum buffer */ /* accum buffer */
strb->Base.InternalFormat = GL_RGBA16_SNORM; rb->InternalFormat = GL_RGBA16_SNORM;
break; break;
case PIPE_FORMAT_R16G16B16A16_UNORM: case PIPE_FORMAT_R16G16B16A16_UNORM:
strb->Base.InternalFormat = GL_RGBA16; rb->InternalFormat = GL_RGBA16;
break; break;
case PIPE_FORMAT_R16G16B16_UNORM: case PIPE_FORMAT_R16G16B16_UNORM:
strb->Base.InternalFormat = GL_RGB16; rb->InternalFormat = GL_RGB16;
break; break;
case PIPE_FORMAT_R8_UNORM: case PIPE_FORMAT_R8_UNORM:
strb->Base.InternalFormat = GL_R8; rb->InternalFormat = GL_R8;
break; break;
case PIPE_FORMAT_R8G8_UNORM: case PIPE_FORMAT_R8G8_UNORM:
strb->Base.InternalFormat = GL_RG8; rb->InternalFormat = GL_RG8;
break; break;
case PIPE_FORMAT_R16_UNORM: case PIPE_FORMAT_R16_UNORM:
strb->Base.InternalFormat = GL_R16; rb->InternalFormat = GL_R16;
break; break;
case PIPE_FORMAT_R16G16_UNORM: case PIPE_FORMAT_R16G16_UNORM:
strb->Base.InternalFormat = GL_RG16; rb->InternalFormat = GL_RG16;
break; break;
case PIPE_FORMAT_R32G32B32A32_FLOAT: case PIPE_FORMAT_R32G32B32A32_FLOAT:
strb->Base.InternalFormat = GL_RGBA32F; rb->InternalFormat = GL_RGBA32F;
break; break;
case PIPE_FORMAT_R32G32B32X32_FLOAT: case PIPE_FORMAT_R32G32B32X32_FLOAT:
case PIPE_FORMAT_R32G32B32_FLOAT: case PIPE_FORMAT_R32G32B32_FLOAT:
strb->Base.InternalFormat = GL_RGB32F; rb->InternalFormat = GL_RGB32F;
break; break;
case PIPE_FORMAT_R16G16B16A16_FLOAT: case PIPE_FORMAT_R16G16B16A16_FLOAT:
strb->Base.InternalFormat = GL_RGBA16F; rb->InternalFormat = GL_RGBA16F;
break; break;
case PIPE_FORMAT_R16G16B16X16_FLOAT: case PIPE_FORMAT_R16G16B16X16_FLOAT:
strb->Base.InternalFormat = GL_RGB16F; rb->InternalFormat = GL_RGB16F;
break; break;
default: default:
_mesa_problem(NULL, _mesa_problem(NULL,
"Unexpected format %s in st_new_renderbuffer_fb", "Unexpected format %s in st_new_renderbuffer_fb",
util_format_name(format)); util_format_name(format));
FREE(strb); FREE(rb);
return NULL; return NULL;
} }
/* st-specific methods */ /* st-specific methods */
strb->Base.Delete = st_renderbuffer_delete; rb->Delete = st_renderbuffer_delete;
strb->Base.AllocStorage = st_renderbuffer_alloc_storage; rb->AllocStorage = st_renderbuffer_alloc_storage;
/* surface is allocated in st_renderbuffer_alloc_storage() */ /* surface is allocated in st_renderbuffer_alloc_storage() */
strb->surface = NULL; rb->surface = NULL;
return &strb->Base; return rb;
} }
void void
st_regen_renderbuffer_surface(struct st_context *st, st_regen_renderbuffer_surface(struct st_context *st,
struct st_renderbuffer *strb) struct gl_renderbuffer *rb)
{ {
struct pipe_context *pipe = st->pipe; struct pipe_context *pipe = st->pipe;
struct pipe_resource *resource = strb->texture; struct pipe_resource *resource = rb->texture;
struct pipe_surface **psurf = struct pipe_surface **psurf =
strb->surface_srgb ? &strb->surface_srgb : &strb->surface_linear; rb->surface_srgb ? &rb->surface_srgb : &rb->surface_linear;
struct pipe_surface *surf = *psurf; struct pipe_surface *surf = *psurf;
/* create a new pipe_surface */ /* create a new pipe_surface */
struct pipe_surface surf_tmpl; struct pipe_surface surf_tmpl;
memset(&surf_tmpl, 0, sizeof(surf_tmpl)); memset(&surf_tmpl, 0, sizeof(surf_tmpl));
surf_tmpl.format = surf->format; surf_tmpl.format = surf->format;
surf_tmpl.nr_samples = strb->rtt_nr_samples; surf_tmpl.nr_samples = rb->rtt_nr_samples;
surf_tmpl.u.tex.level = surf->u.tex.level; surf_tmpl.u.tex.level = surf->u.tex.level;
surf_tmpl.u.tex.first_layer = surf->u.tex.first_layer; surf_tmpl.u.tex.first_layer = surf->u.tex.first_layer;
surf_tmpl.u.tex.last_layer = surf->u.tex.last_layer; surf_tmpl.u.tex.last_layer = surf->u.tex.last_layer;
@ -471,7 +468,7 @@ st_regen_renderbuffer_surface(struct st_context *st,
pipe_surface_release(pipe, psurf); pipe_surface_release(pipe, psurf);
*psurf = surf; *psurf = surf;
strb->surface = *psurf; rb->surface = *psurf;
} }
/** /**
@ -480,27 +477,27 @@ st_regen_renderbuffer_surface(struct st_context *st,
*/ */
void void
st_update_renderbuffer_surface(struct st_context *st, st_update_renderbuffer_surface(struct st_context *st,
struct st_renderbuffer *strb) struct gl_renderbuffer *rb)
{ {
struct pipe_context *pipe = st->pipe; struct pipe_context *pipe = st->pipe;
struct pipe_resource *resource = strb->texture; struct pipe_resource *resource = rb->texture;
const struct gl_texture_object *stTexObj = NULL; const struct gl_texture_object *stTexObj = NULL;
unsigned rtt_width = strb->Base.Width; unsigned rtt_width = rb->Width;
unsigned rtt_height = strb->Base.Height; unsigned rtt_height = rb->Height;
unsigned rtt_depth = strb->Base.Depth; unsigned rtt_depth = rb->Depth;
/* /*
* For winsys fbo, it is possible that the renderbuffer is sRGB-capable but * For winsys fbo, it is possible that the renderbuffer is sRGB-capable but
* the format of strb->texture is linear (because we have no control over * the format of rb->texture is linear (because we have no control over
* the format). Check strb->Base.Format instead of strb->texture->format * the format). Check rb->Format instead of rb->texture->format
* to determine if the rb is sRGB-capable. * to determine if the rb is sRGB-capable.
*/ */
boolean enable_srgb = st->ctx->Color.sRGBEnabled && boolean enable_srgb = st->ctx->Color.sRGBEnabled &&
_mesa_is_format_srgb(strb->Base.Format); _mesa_is_format_srgb(rb->Format);
enum pipe_format format = resource->format; enum pipe_format format = resource->format;
if (strb->is_rtt) { if (rb->is_rtt) {
stTexObj = strb->Base.TexImage->TexObject; stTexObj = rb->TexImage->TexObject;
if (stTexObj->surface_based) if (stTexObj->surface_based)
format = stTexObj->surface_format; format = stTexObj->surface_format;
} }
@ -526,21 +523,21 @@ st_update_renderbuffer_surface(struct st_context *st,
/* determine the layer bounds */ /* determine the layer bounds */
unsigned first_layer, last_layer; unsigned first_layer, last_layer;
if (strb->rtt_layered) { if (rb->rtt_layered) {
first_layer = 0; first_layer = 0;
last_layer = util_max_layer(strb->texture, level); last_layer = util_max_layer(rb->texture, level);
} }
else { else {
first_layer = first_layer =
last_layer = strb->rtt_face + strb->rtt_slice; last_layer = rb->rtt_face + rb->rtt_slice;
} }
/* Adjust for texture views */ /* Adjust for texture views */
if (strb->is_rtt && resource->array_size > 1 && if (rb->is_rtt && resource->array_size > 1 &&
stTexObj->Immutable) { stTexObj->Immutable) {
const struct gl_texture_object *tex = stTexObj; const struct gl_texture_object *tex = stTexObj;
first_layer += tex->Attrib.MinLayer; first_layer += tex->Attrib.MinLayer;
if (!strb->rtt_layered) if (!rb->rtt_layered)
last_layer += tex->Attrib.MinLayer; last_layer += tex->Attrib.MinLayer;
else else
last_layer = MIN2(first_layer + tex->Attrib.NumLayers - 1, last_layer = MIN2(first_layer + tex->Attrib.NumLayers - 1,
@ -548,17 +545,17 @@ st_update_renderbuffer_surface(struct st_context *st,
} }
struct pipe_surface **psurf = struct pipe_surface **psurf =
enable_srgb ? &strb->surface_srgb : &strb->surface_linear; enable_srgb ? &rb->surface_srgb : &rb->surface_linear;
struct pipe_surface *surf = *psurf; struct pipe_surface *surf = *psurf;
if (!surf || if (!surf ||
surf->texture->nr_samples != strb->Base.NumSamples || surf->texture->nr_samples != rb->NumSamples ||
surf->texture->nr_storage_samples != strb->Base.NumStorageSamples || surf->texture->nr_storage_samples != rb->NumStorageSamples ||
surf->format != format || surf->format != format ||
surf->texture != resource || surf->texture != resource ||
surf->width != rtt_width || surf->width != rtt_width ||
surf->height != rtt_height || surf->height != rtt_height ||
surf->nr_samples != strb->rtt_nr_samples || surf->nr_samples != rb->rtt_nr_samples ||
surf->u.tex.level != level || surf->u.tex.level != level ||
surf->u.tex.first_layer != first_layer || surf->u.tex.first_layer != first_layer ||
surf->u.tex.last_layer != last_layer) { surf->u.tex.last_layer != last_layer) {
@ -566,7 +563,7 @@ st_update_renderbuffer_surface(struct st_context *st,
struct pipe_surface surf_tmpl; struct pipe_surface surf_tmpl;
memset(&surf_tmpl, 0, sizeof(surf_tmpl)); memset(&surf_tmpl, 0, sizeof(surf_tmpl));
surf_tmpl.format = format; surf_tmpl.format = format;
surf_tmpl.nr_samples = strb->rtt_nr_samples; surf_tmpl.nr_samples = rb->rtt_nr_samples;
surf_tmpl.u.tex.level = level; surf_tmpl.u.tex.level = level;
surf_tmpl.u.tex.first_layer = first_layer; surf_tmpl.u.tex.first_layer = first_layer;
surf_tmpl.u.tex.last_layer = last_layer; surf_tmpl.u.tex.last_layer = last_layer;
@ -576,7 +573,7 @@ st_update_renderbuffer_surface(struct st_context *st,
pipe_surface_release(pipe, psurf); pipe_surface_release(pipe, psurf);
*psurf = surf; *psurf = surf;
} }
strb->surface = *psurf; rb->surface = *psurf;
} }
@ -604,7 +601,6 @@ st_render_texture(struct gl_context *ctx,
{ {
struct st_context *st = st_context(ctx); struct st_context *st = st_context(ctx);
struct gl_renderbuffer *rb = att->Renderbuffer; struct gl_renderbuffer *rb = att->Renderbuffer;
struct st_renderbuffer *strb = st_renderbuffer(rb);
struct pipe_resource *pt; struct pipe_resource *pt;
pt = get_teximage_resource(att->Texture, pt = get_teximage_resource(att->Texture,
@ -613,14 +609,14 @@ st_render_texture(struct gl_context *ctx,
assert(pt); assert(pt);
/* point renderbuffer at texobject */ /* point renderbuffer at texobject */
strb->is_rtt = TRUE; rb->is_rtt = TRUE;
strb->rtt_face = att->CubeMapFace; rb->rtt_face = att->CubeMapFace;
strb->rtt_slice = att->Zoffset; rb->rtt_slice = att->Zoffset;
strb->rtt_layered = att->Layered; rb->rtt_layered = att->Layered;
strb->rtt_nr_samples = att->NumSamples; rb->rtt_nr_samples = att->NumSamples;
pipe_resource_reference(&strb->texture, pt); pipe_resource_reference(&rb->texture, pt);
st_update_renderbuffer_surface(st, strb); st_update_renderbuffer_surface(st, rb);
/* Invalidate buffer state so that the pipe's framebuffer state /* Invalidate buffer state so that the pipe's framebuffer state
* gets updated. * gets updated.
@ -644,12 +640,11 @@ void
st_finish_render_texture(struct gl_context *ctx, struct gl_renderbuffer *rb) st_finish_render_texture(struct gl_context *ctx, struct gl_renderbuffer *rb)
{ {
struct st_context *st = st_context(ctx); struct st_context *st = st_context(ctx);
struct st_renderbuffer *strb = st_renderbuffer(rb);
if (!strb) if (!rb)
return; return;
strb->is_rtt = FALSE; rb->is_rtt = FALSE;
/* restore previous framebuffer state */ /* restore previous framebuffer state */
st_invalidate_buffers(st); st_invalidate_buffers(st);
@ -784,7 +779,7 @@ st_validate_framebuffer(struct gl_context *ctx, struct gl_framebuffer *fb)
if (!mixed_formats) { if (!mixed_formats) {
/* Disallow mixed formats. */ /* Disallow mixed formats. */
if (att->Type != GL_NONE) { if (att->Type != GL_NONE) {
format = st_renderbuffer(att->Renderbuffer)->surface->format; format = att->Renderbuffer->surface->format;
} else { } else {
continue; continue;
} }
@ -814,7 +809,7 @@ st_discard_framebuffer(struct gl_context *ctx, struct gl_framebuffer *fb,
if (!att->Renderbuffer || !att->Complete) if (!att->Renderbuffer || !att->Complete)
return; return;
prsc = st_renderbuffer(att->Renderbuffer)->surface->texture; prsc = att->Renderbuffer->surface->texture;
/* using invalidate_resource will only work for simple 2D resources */ /* using invalidate_resource will only work for simple 2D resources */
if (prsc->depth0 != 1 || prsc->array_size != 1 || prsc->last_level != 0) if (prsc->depth0 != 1 || prsc->array_size != 1 || prsc->last_level != 0)
@ -894,19 +889,18 @@ st_MapRenderbuffer(struct gl_context *ctx,
bool flip_y) bool flip_y)
{ {
struct st_context *st = st_context(ctx); struct st_context *st = st_context(ctx);
struct st_renderbuffer *strb = st_renderbuffer(rb);
struct pipe_context *pipe = st->pipe; struct pipe_context *pipe = st->pipe;
const GLboolean invert = flip_y; const GLboolean invert = flip_y;
GLuint y2; GLuint y2;
GLubyte *map; GLubyte *map;
if (strb->software) { if (rb->software) {
/* software-allocated renderbuffer (probably an accum buffer) */ /* software-allocated renderbuffer (probably an accum buffer) */
if (strb->data) { if (rb->data) {
GLint bpp = _mesa_get_format_bytes(strb->Base.Format); GLint bpp = _mesa_get_format_bytes(rb->Format);
GLint stride = _mesa_format_row_stride(strb->Base.Format, GLint stride = _mesa_format_row_stride(rb->Format,
strb->Base.Width); rb->Width);
*mapOut = (GLubyte *) strb->data + y * stride + x * bpp; *mapOut = (GLubyte *) rb->data + y * stride + x * bpp;
*rowStrideOut = stride; *rowStrideOut = stride;
} }
else { else {
@ -929,22 +923,22 @@ st_MapRenderbuffer(struct gl_context *ctx,
* user-allocated renderbuffers and textures. * user-allocated renderbuffers and textures.
*/ */
if (invert) if (invert)
y2 = strb->Base.Height - y - h; y2 = rb->Height - y - h;
else else
y2 = y; y2 = y;
map = pipe_texture_map(pipe, map = pipe_texture_map(pipe,
strb->texture, rb->texture,
strb->surface->u.tex.level, rb->surface->u.tex.level,
strb->surface->u.tex.first_layer, rb->surface->u.tex.first_layer,
transfer_flags, x, y2, w, h, &strb->transfer); transfer_flags, x, y2, w, h, &rb->transfer);
if (map) { if (map) {
if (invert) { if (invert) {
*rowStrideOut = -(int) strb->transfer->stride; *rowStrideOut = -(int) rb->transfer->stride;
map += (h - 1) * strb->transfer->stride; map += (h - 1) * rb->transfer->stride;
} }
else { else {
*rowStrideOut = strb->transfer->stride; *rowStrideOut = rb->transfer->stride;
} }
*mapOut = map; *mapOut = map;
} }
@ -963,14 +957,13 @@ st_UnmapRenderbuffer(struct gl_context *ctx,
struct gl_renderbuffer *rb) struct gl_renderbuffer *rb)
{ {
struct st_context *st = st_context(ctx); struct st_context *st = st_context(ctx);
struct st_renderbuffer *strb = st_renderbuffer(rb);
struct pipe_context *pipe = st->pipe; struct pipe_context *pipe = st->pipe;
if (strb->software) { if (rb->software) {
/* software-allocated renderbuffer (probably an accum buffer) */ /* software-allocated renderbuffer (probably an accum buffer) */
return; return;
} }
pipe_texture_unmap(pipe, strb->transfer); pipe_texture_unmap(pipe, rb->transfer);
strb->transfer = NULL; rb->transfer = NULL;
} }

View File

@ -39,50 +39,10 @@
struct dd_function_table; struct dd_function_table;
struct pipe_context; struct pipe_context;
/**
* Derived renderbuffer class. Just need to add a pointer to the
* pipe surface.
*/
struct st_renderbuffer
{
struct gl_renderbuffer Base;
struct pipe_resource *texture;
/* This points to either "surface_linear" or "surface_srgb".
* It doesn't hold the pipe_surface reference. The other two do.
*/
struct pipe_surface *surface;
struct pipe_surface *surface_linear;
struct pipe_surface *surface_srgb;
GLboolean defined; /**< defined contents? */
struct pipe_transfer *transfer; /**< only used when mapping the resource */
/**
* Used only when hardware accumulation buffers are not supported.
*/
boolean software;
void *data;
bool use_readpix_cache;
/* Inputs from Driver.RenderTexture, don't use directly. */
boolean is_rtt; /**< whether Driver.RenderTexture was called */
unsigned rtt_face, rtt_slice;
boolean rtt_layered; /**< whether glFramebufferTexture was called */
unsigned rtt_nr_samples; /**< from FramebufferTexture2DMultisampleEXT */
};
static inline struct st_renderbuffer *
st_renderbuffer(struct gl_renderbuffer *rb)
{
return (struct st_renderbuffer *) rb;
}
static inline struct pipe_resource * static inline struct pipe_resource *
st_get_renderbuffer_resource(struct gl_renderbuffer *rb) st_get_renderbuffer_resource(struct gl_renderbuffer *rb)
{ {
return st_renderbuffer(rb)->texture; return rb->texture;
} }
/** /**
@ -107,11 +67,11 @@ st_new_renderbuffer_fb(enum pipe_format format, unsigned samples, boolean sw);
extern void extern void
st_update_renderbuffer_surface(struct st_context *st, st_update_renderbuffer_surface(struct st_context *st,
struct st_renderbuffer *strb); struct gl_renderbuffer *strb);
extern void extern void
st_regen_renderbuffer_surface(struct st_context *st, st_regen_renderbuffer_surface(struct st_context *st,
struct st_renderbuffer *strb); struct gl_renderbuffer *strb);
struct gl_renderbuffer *st_new_renderbuffer(struct gl_context *ctx, GLuint name); struct gl_renderbuffer *st_new_renderbuffer(struct gl_context *ctx, GLuint name);
void st_render_texture(struct gl_context *ctx, void st_render_texture(struct gl_context *ctx,

View File

@ -94,7 +94,7 @@ needs_integer_signed_unsigned_conversion(const struct gl_context *ctx,
} }
static bool static bool
try_pbo_readpixels(struct st_context *st, struct st_renderbuffer *strb, try_pbo_readpixels(struct st_context *st, struct gl_renderbuffer *rb,
bool invert_y, bool invert_y,
GLint x, GLint y, GLsizei width, GLsizei height, GLint x, GLint y, GLsizei width, GLsizei height,
GLenum gl_format, GLenum gl_format,
@ -104,8 +104,8 @@ try_pbo_readpixels(struct st_context *st, struct st_renderbuffer *strb,
struct pipe_context *pipe = st->pipe; struct pipe_context *pipe = st->pipe;
struct pipe_screen *screen = st->screen; struct pipe_screen *screen = st->screen;
struct cso_context *cso = st->cso_context; struct cso_context *cso = st->cso_context;
struct pipe_surface *surface = strb->surface; struct pipe_surface *surface = rb->surface;
struct pipe_resource *texture = strb->texture; struct pipe_resource *texture = rb->texture;
const struct util_format_description *desc; const struct util_format_description *desc;
struct st_pbo_addresses addr; struct st_pbo_addresses addr;
struct pipe_framebuffer_state fb; struct pipe_framebuffer_state fb;
@ -273,7 +273,7 @@ fail:
* Create a staging texture and blit the requested region to it. * Create a staging texture and blit the requested region to it.
*/ */
static struct pipe_resource * static struct pipe_resource *
blit_to_staging(struct st_context *st, struct st_renderbuffer *strb, blit_to_staging(struct st_context *st, struct gl_renderbuffer *rb,
bool invert_y, bool invert_y,
GLint x, GLint y, GLsizei width, GLsizei height, GLint x, GLint y, GLsizei width, GLsizei height,
GLenum format, GLenum format,
@ -310,8 +310,8 @@ blit_to_staging(struct st_context *st, struct st_renderbuffer *strb,
return NULL; return NULL;
memset(&blit, 0, sizeof(blit)); memset(&blit, 0, sizeof(blit));
blit.src.resource = strb->texture; blit.src.resource = rb->texture;
blit.src.level = strb->surface->u.tex.level; blit.src.level = rb->surface->u.tex.level;
blit.src.format = src_format; blit.src.format = src_format;
blit.dst.resource = dst; blit.dst.resource = dst;
blit.dst.level = 0; blit.dst.level = 0;
@ -320,17 +320,17 @@ blit_to_staging(struct st_context *st, struct st_renderbuffer *strb,
blit.dst.box.x = 0; blit.dst.box.x = 0;
blit.src.box.y = y; blit.src.box.y = y;
blit.dst.box.y = 0; blit.dst.box.y = 0;
blit.src.box.z = strb->surface->u.tex.first_layer; blit.src.box.z = rb->surface->u.tex.first_layer;
blit.dst.box.z = 0; blit.dst.box.z = 0;
blit.src.box.width = blit.dst.box.width = width; blit.src.box.width = blit.dst.box.width = width;
blit.src.box.height = blit.dst.box.height = height; blit.src.box.height = blit.dst.box.height = height;
blit.src.box.depth = blit.dst.box.depth = 1; blit.src.box.depth = blit.dst.box.depth = 1;
blit.mask = st_get_blit_mask(strb->Base._BaseFormat, format); blit.mask = st_get_blit_mask(rb->_BaseFormat, format);
blit.filter = PIPE_TEX_FILTER_NEAREST; blit.filter = PIPE_TEX_FILTER_NEAREST;
blit.scissor_enable = FALSE; blit.scissor_enable = FALSE;
if (invert_y) { if (invert_y) {
blit.src.box.y = strb->Base.Height - blit.src.box.y; blit.src.box.y = rb->Height - blit.src.box.y;
blit.src.box.height = -blit.src.box.height; blit.src.box.height = -blit.src.box.height;
} }
@ -341,13 +341,13 @@ blit_to_staging(struct st_context *st, struct st_renderbuffer *strb,
} }
static struct pipe_resource * static struct pipe_resource *
try_cached_readpixels(struct st_context *st, struct st_renderbuffer *strb, try_cached_readpixels(struct st_context *st, struct gl_renderbuffer *rb,
bool invert_y, bool invert_y,
GLsizei width, GLsizei height, GLsizei width, GLsizei height,
GLenum format, GLenum format,
enum pipe_format src_format, enum pipe_format dst_format) enum pipe_format src_format, enum pipe_format dst_format)
{ {
struct pipe_resource *src = strb->texture; struct pipe_resource *src = rb->texture;
struct pipe_resource *dst = NULL; struct pipe_resource *dst = NULL;
if (ST_DEBUG & DEBUG_NOREADPIXCACHE) if (ST_DEBUG & DEBUG_NOREADPIXCACHE)
@ -356,37 +356,37 @@ try_cached_readpixels(struct st_context *st, struct st_renderbuffer *strb,
/* Reset cache after invalidation or switch of parameters. */ /* Reset cache after invalidation or switch of parameters. */
if (st->readpix_cache.src != src || if (st->readpix_cache.src != src ||
st->readpix_cache.dst_format != dst_format || st->readpix_cache.dst_format != dst_format ||
st->readpix_cache.level != strb->surface->u.tex.level || st->readpix_cache.level != rb->surface->u.tex.level ||
st->readpix_cache.layer != strb->surface->u.tex.first_layer) { st->readpix_cache.layer != rb->surface->u.tex.first_layer) {
pipe_resource_reference(&st->readpix_cache.src, src); pipe_resource_reference(&st->readpix_cache.src, src);
pipe_resource_reference(&st->readpix_cache.cache, NULL); pipe_resource_reference(&st->readpix_cache.cache, NULL);
st->readpix_cache.dst_format = dst_format; st->readpix_cache.dst_format = dst_format;
st->readpix_cache.level = strb->surface->u.tex.level; st->readpix_cache.level = rb->surface->u.tex.level;
st->readpix_cache.layer = strb->surface->u.tex.first_layer; st->readpix_cache.layer = rb->surface->u.tex.first_layer;
st->readpix_cache.hits = 0; st->readpix_cache.hits = 0;
} }
/* Decide whether to trigger the cache. */ /* Decide whether to trigger the cache. */
if (!st->readpix_cache.cache) { if (!st->readpix_cache.cache) {
if (!strb->use_readpix_cache && !ALWAYS_READPIXELS_CACHE) { if (!rb->use_readpix_cache && !ALWAYS_READPIXELS_CACHE) {
/* Heuristic: If previous successive calls read at least a fraction /* Heuristic: If previous successive calls read at least a fraction
* of the surface _and_ we read again, trigger the cache. * of the surface _and_ we read again, trigger the cache.
*/ */
unsigned threshold = MAX2(1, strb->Base.Width * strb->Base.Height / 8); unsigned threshold = MAX2(1, rb->Width * rb->Height / 8);
if (st->readpix_cache.hits < threshold) { if (st->readpix_cache.hits < threshold) {
st->readpix_cache.hits += width * height; st->readpix_cache.hits += width * height;
return NULL; return NULL;
} }
strb->use_readpix_cache = true; rb->use_readpix_cache = true;
} }
/* Fill the cache */ /* Fill the cache */
st->readpix_cache.cache = blit_to_staging(st, strb, invert_y, st->readpix_cache.cache = blit_to_staging(st, rb, invert_y,
0, 0, 0, 0,
strb->Base.Width, rb->Width,
strb->Base.Height, format, rb->Height, format,
src_format, dst_format); src_format, dst_format);
} }
@ -418,7 +418,6 @@ st_ReadPixels(struct gl_context *ctx, GLint x, GLint y,
struct st_context *st = st_context(ctx); struct st_context *st = st_context(ctx);
struct gl_renderbuffer *rb = struct gl_renderbuffer *rb =
_mesa_get_read_renderbuffer_for_format(ctx, format); _mesa_get_read_renderbuffer_for_format(ctx, format);
struct st_renderbuffer *strb = st_renderbuffer(rb);
struct pipe_context *pipe = st->pipe; struct pipe_context *pipe = st->pipe;
struct pipe_screen *screen = st->screen; struct pipe_screen *screen = st->screen;
struct pipe_resource *src; struct pipe_resource *src;
@ -439,7 +438,7 @@ st_ReadPixels(struct gl_context *ctx, GLint x, GLint y,
} }
/* This must be done after state validation. */ /* This must be done after state validation. */
src = strb->texture; src = rb->texture;
/* XXX Fallback for depth-stencil formats due to an incomplete /* XXX Fallback for depth-stencil formats due to an incomplete
* stencil blit implementation in some drivers. */ * stencil blit implementation in some drivers. */
@ -460,7 +459,7 @@ st_ReadPixels(struct gl_context *ctx, GLint x, GLint y,
/* Convert the source format to what is expected by ReadPixels /* Convert the source format to what is expected by ReadPixels
* and see if it's supported. */ * and see if it's supported. */
src_format = util_format_linear(strb->Base.Format); src_format = util_format_linear(rb->Format);
src_format = util_format_luminance_to_red(src_format); src_format = util_format_luminance_to_red(src_format);
src_format = util_format_intensity_to_red(src_format); src_format = util_format_intensity_to_red(src_format);
@ -485,7 +484,7 @@ st_ReadPixels(struct gl_context *ctx, GLint x, GLint y,
} }
if (st->pbo.download_enabled && pack->BufferObj) { if (st->pbo.download_enabled && pack->BufferObj) {
if (try_pbo_readpixels(st, strb, if (try_pbo_readpixels(st, rb,
st_fb_orientation(ctx->ReadBuffer) == Y_0_TOP, st_fb_orientation(ctx->ReadBuffer) == Y_0_TOP,
x, y, width, height, x, y, width, height,
format, src_format, dst_format, format, src_format, dst_format,
@ -500,7 +499,7 @@ st_ReadPixels(struct gl_context *ctx, GLint x, GLint y,
/* Cache a staging texture for back-to-back ReadPixels, to avoid CPU-GPU /* Cache a staging texture for back-to-back ReadPixels, to avoid CPU-GPU
* synchronization overhead. * synchronization overhead.
*/ */
dst = try_cached_readpixels(st, strb, dst = try_cached_readpixels(st, rb,
st_fb_orientation(ctx->ReadBuffer) == Y_0_TOP, st_fb_orientation(ctx->ReadBuffer) == Y_0_TOP,
width, height, format, src_format, dst_format); width, height, format, src_format, dst_format);
if (dst) { if (dst) {
@ -515,7 +514,7 @@ st_ReadPixels(struct gl_context *ctx, GLint x, GLint y,
goto fallback; goto fallback;
} }
dst = blit_to_staging(st, strb, dst = blit_to_staging(st, rb,
st_fb_orientation(ctx->ReadBuffer) == Y_0_TOP, st_fb_orientation(ctx->ReadBuffer) == Y_0_TOP,
x, y, width, height, format, x, y, width, height, format,
src_format, dst_format); src_format, dst_format);

View File

@ -2545,7 +2545,7 @@ cpu_transfer:
*/ */
static void static void
fallback_copy_texsubimage(struct gl_context *ctx, fallback_copy_texsubimage(struct gl_context *ctx,
struct st_renderbuffer *strb, struct gl_renderbuffer *rb,
struct gl_texture_image *stImage, struct gl_texture_image *stImage,
GLenum baseFormat, GLenum baseFormat,
GLint destX, GLint destY, GLint slice, GLint destX, GLint destY, GLint slice,
@ -2567,13 +2567,13 @@ fallback_copy_texsubimage(struct gl_context *ctx,
debug_printf("%s: fallback processing\n", __func__); debug_printf("%s: fallback processing\n", __func__);
if (st_fb_orientation(ctx->ReadBuffer) == Y_0_TOP) { if (st_fb_orientation(ctx->ReadBuffer) == Y_0_TOP) {
srcY = strb->Base.Height - srcY - height; srcY = rb->Height - srcY - height;
} }
map = pipe_texture_map(pipe, map = pipe_texture_map(pipe,
strb->texture, rb->texture,
strb->surface->u.tex.level, rb->surface->u.tex.level,
strb->surface->u.tex.first_layer, rb->surface->u.tex.first_layer,
PIPE_MAP_READ, PIPE_MAP_READ,
srcX, srcY, srcX, srcY,
width, height, &src_trans); width, height, &src_trans);
@ -2622,7 +2622,7 @@ fallback_copy_texsubimage(struct gl_context *ctx,
transfer->layer_stride : transfer->stride); transfer->layer_stride : transfer->stride);
/* To avoid a large temp memory allocation, do copy row by row */ /* To avoid a large temp memory allocation, do copy row by row */
for (row = 0; row < height; row++, srcY += yStep) { for (row = 0; row < height; row++, srcY += yStep) {
util_format_unpack_z_32unorm(strb->texture->format, util_format_unpack_z_32unorm(rb->texture->format,
data, (uint8_t *)map + src_trans->stride * srcY, data, (uint8_t *)map + src_trans->stride * srcY,
width); width);
if (scaleOrBias) { if (scaleOrBias) {
@ -2666,7 +2666,7 @@ fallback_copy_texsubimage(struct gl_context *ctx,
* try to avoid that someday. * try to avoid that someday.
*/ */
pipe_get_tile_rgba(src_trans, map, 0, 0, width, height, pipe_get_tile_rgba(src_trans, map, 0, 0, width, height,
util_format_linear(strb->texture->format), util_format_linear(rb->texture->format),
tempSrc); tempSrc);
/* Store into texture memory. /* Store into texture memory.
@ -2740,7 +2740,6 @@ st_CopyTexSubImage(struct gl_context *ctx, GLuint dims,
{ {
struct gl_texture_image *stImage = texImage; struct gl_texture_image *stImage = texImage;
struct gl_texture_object *stObj = texImage->TexObject; struct gl_texture_object *stObj = texImage->TexObject;
struct st_renderbuffer *strb = st_renderbuffer(rb);
struct st_context *st = st_context(ctx); struct st_context *st = st_context(ctx);
struct pipe_context *pipe = st->pipe; struct pipe_context *pipe = st->pipe;
struct pipe_screen *screen = st->screen; struct pipe_screen *screen = st->screen;
@ -2757,8 +2756,8 @@ st_CopyTexSubImage(struct gl_context *ctx, GLuint dims,
!_mesa_is_format_astc_2d(texImage->TexFormat) && !_mesa_is_format_astc_2d(texImage->TexFormat) &&
texImage->TexFormat != MESA_FORMAT_ETC1_RGB8); texImage->TexFormat != MESA_FORMAT_ETC1_RGB8);
if (!strb || !strb->surface || !stImage->pt) { if (!rb || !rb->surface || !stImage->pt) {
debug_printf("%s: null strb or stImage\n", __func__); debug_printf("%s: null rb or stImage\n", __func__);
return; return;
} }
@ -2794,7 +2793,7 @@ st_CopyTexSubImage(struct gl_context *ctx, GLuint dims,
/* Y flipping for the main framebuffer. */ /* Y flipping for the main framebuffer. */
if (do_flip) { if (do_flip) {
srcY1 = strb->Base.Height - srcY - height; srcY1 = rb->Height - srcY - height;
srcY0 = srcY1 + height; srcY0 = srcY1 + height;
} }
else { else {
@ -2806,12 +2805,12 @@ st_CopyTexSubImage(struct gl_context *ctx, GLuint dims,
* This supports flipping, format conversions, and downsampling. * This supports flipping, format conversions, and downsampling.
*/ */
memset(&blit, 0, sizeof(blit)); memset(&blit, 0, sizeof(blit));
blit.src.resource = strb->texture; blit.src.resource = rb->texture;
blit.src.format = util_format_linear(strb->surface->format); blit.src.format = util_format_linear(rb->surface->format);
blit.src.level = strb->surface->u.tex.level; blit.src.level = rb->surface->u.tex.level;
blit.src.box.x = srcX; blit.src.box.x = srcX;
blit.src.box.y = srcY0; blit.src.box.y = srcY0;
blit.src.box.z = strb->surface->u.tex.first_layer; blit.src.box.z = rb->surface->u.tex.first_layer;
blit.src.box.width = width; blit.src.box.width = width;
blit.src.box.height = srcY1 - srcY0; blit.src.box.height = srcY1 - srcY0;
blit.src.box.depth = 1; blit.src.box.depth = 1;
@ -2834,7 +2833,7 @@ st_CopyTexSubImage(struct gl_context *ctx, GLuint dims,
fallback: fallback:
/* software fallback */ /* software fallback */
fallback_copy_texsubimage(ctx, fallback_copy_texsubimage(ctx,
strb, stImage, texImage->_BaseFormat, rb, stImage, texImage->_BaseFormat,
destX, destY, slice, destX, destY, slice,
srcX, srcY, width, height); srcX, srcY, width, height);
} }

View File

@ -174,22 +174,22 @@ st_context_validate(struct st_context *st,
void void
st_set_ws_renderbuffer_surface(struct st_renderbuffer *strb, st_set_ws_renderbuffer_surface(struct gl_renderbuffer *rb,
struct pipe_surface *surf) struct pipe_surface *surf)
{ {
pipe_surface_reference(&strb->surface_srgb, NULL); pipe_surface_reference(&rb->surface_srgb, NULL);
pipe_surface_reference(&strb->surface_linear, NULL); pipe_surface_reference(&rb->surface_linear, NULL);
if (util_format_is_srgb(surf->format)) if (util_format_is_srgb(surf->format))
pipe_surface_reference(&strb->surface_srgb, surf); pipe_surface_reference(&rb->surface_srgb, surf);
else else
pipe_surface_reference(&strb->surface_linear, surf); pipe_surface_reference(&rb->surface_linear, surf);
strb->surface = surf; /* just assign, don't ref */ rb->surface = surf; /* just assign, don't ref */
pipe_resource_reference(&strb->texture, surf->texture); pipe_resource_reference(&rb->texture, surf->texture);
strb->Base.Width = surf->width; rb->Width = surf->width;
strb->Base.Height = surf->height; rb->Height = surf->height;
} }
@ -231,7 +231,7 @@ st_framebuffer_validate(struct st_framebuffer *stfb,
height = stfb->Base.Height; height = stfb->Base.Height;
for (i = 0; i < stfb->num_statts; i++) { for (i = 0; i < stfb->num_statts; i++) {
struct st_renderbuffer *strb; struct gl_renderbuffer *rb;
struct pipe_surface *ps, surf_tmpl; struct pipe_surface *ps, surf_tmpl;
gl_buffer_index idx; gl_buffer_index idx;
@ -244,9 +244,9 @@ st_framebuffer_validate(struct st_framebuffer *stfb,
continue; continue;
} }
strb = st_renderbuffer(stfb->Base.Attachment[idx].Renderbuffer); rb = stfb->Base.Attachment[idx].Renderbuffer;
assert(strb); assert(rb);
if (strb->texture == textures[i]) { if (rb->texture == textures[i]) {
pipe_resource_reference(&textures[i], NULL); pipe_resource_reference(&textures[i], NULL);
continue; continue;
} }
@ -254,13 +254,13 @@ st_framebuffer_validate(struct st_framebuffer *stfb,
u_surface_default_template(&surf_tmpl, textures[i]); u_surface_default_template(&surf_tmpl, textures[i]);
ps = st->pipe->create_surface(st->pipe, textures[i], &surf_tmpl); ps = st->pipe->create_surface(st->pipe, textures[i], &surf_tmpl);
if (ps) { if (ps) {
st_set_ws_renderbuffer_surface(strb, ps); st_set_ws_renderbuffer_surface(rb, ps);
pipe_surface_reference(&ps, NULL); pipe_surface_reference(&ps, NULL);
changed = true; changed = true;
width = strb->Base.Width; width = rb->Width;
height = strb->Base.Height; height = rb->Height;
} }
pipe_resource_reference(&textures[i], NULL); pipe_resource_reference(&textures[i], NULL);
@ -287,11 +287,11 @@ st_framebuffer_update_attachments(struct st_framebuffer *stfb)
stfb->statts[i] = ST_ATTACHMENT_INVALID; stfb->statts[i] = ST_ATTACHMENT_INVALID;
for (idx = 0; idx < BUFFER_COUNT; idx++) { for (idx = 0; idx < BUFFER_COUNT; idx++) {
struct st_renderbuffer *strb; struct gl_renderbuffer *rb;
enum st_attachment_type statt; enum st_attachment_type statt;
strb = st_renderbuffer(stfb->Base.Attachment[idx].Renderbuffer); rb = stfb->Base.Attachment[idx].Renderbuffer;
if (!strb || strb->software) if (!rb || rb->software)
continue; continue;
statt = buffer_index_to_attachment(idx); statt = buffer_index_to_attachment(idx);
@ -1153,7 +1153,7 @@ void
st_manager_flush_frontbuffer(struct st_context *st) st_manager_flush_frontbuffer(struct st_context *st)
{ {
struct st_framebuffer *stfb = st_ws_framebuffer(st->ctx->DrawBuffer); struct st_framebuffer *stfb = st_ws_framebuffer(st->ctx->DrawBuffer);
struct st_renderbuffer *strb = NULL; struct gl_renderbuffer *rb = NULL;
if (!stfb) if (!stfb)
return; return;
@ -1168,23 +1168,21 @@ st_manager_flush_frontbuffer(struct st_context *st)
/* Check front buffer used at the GL API level. */ /* Check front buffer used at the GL API level. */
enum st_attachment_type statt = ST_ATTACHMENT_FRONT_LEFT; enum st_attachment_type statt = ST_ATTACHMENT_FRONT_LEFT;
strb = st_renderbuffer(stfb->Base.Attachment[BUFFER_FRONT_LEFT]. rb = stfb->Base.Attachment[BUFFER_FRONT_LEFT].Renderbuffer;
Renderbuffer); if (!rb) {
if (!strb) {
/* Check back buffer redirected by EGL_KHR_mutable_render_buffer. */ /* Check back buffer redirected by EGL_KHR_mutable_render_buffer. */
statt = ST_ATTACHMENT_BACK_LEFT; statt = ST_ATTACHMENT_BACK_LEFT;
strb = st_renderbuffer(stfb->Base.Attachment[BUFFER_BACK_LEFT]. rb = stfb->Base.Attachment[BUFFER_BACK_LEFT].Renderbuffer;
Renderbuffer);
} }
/* Do we have a front color buffer and has it been drawn to since last /* Do we have a front color buffer and has it been drawn to since last
* frontbuffer flush? * frontbuffer flush?
*/ */
if (strb && strb->defined && if (rb && rb->defined &&
stfb->iface->flush_front(&st->iface, stfb->iface, statt)) { stfb->iface->flush_front(&st->iface, stfb->iface, statt)) {
strb->defined = GL_FALSE; rb->defined = GL_FALSE;
/* Trigger an update of strb->defined on next draw */ /* Trigger an update of rb->defined on next draw */
st->dirty |= ST_NEW_FB_STATE; st->dirty |= ST_NEW_FB_STATE;
} }
} }

View File

@ -35,7 +35,7 @@
struct st_context; struct st_context;
struct st_framebuffer; struct st_framebuffer;
struct st_framebuffer_interface; struct st_framebuffer_interface;
struct st_renderbuffer; struct gl_renderbuffer;
struct pipe_surface; struct pipe_surface;
void void
@ -59,7 +59,7 @@ void
st_manager_flush_swapbuffers(void); st_manager_flush_swapbuffers(void);
void void
st_set_ws_renderbuffer_surface(struct st_renderbuffer *strb, st_set_ws_renderbuffer_surface(struct gl_renderbuffer *rb,
struct pipe_surface *surf); struct pipe_surface *surf);
#endif /* ST_MANAGER_H */ #endif /* ST_MANAGER_H */