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
* required by the OpenCL implementation on the device."
*/
res = st_renderbuffer(rb)->texture;
res = rb->texture;
if (!res) {
simple_mtx_unlock(&ctx->Shared->Mutex);
return MESA_GLINTEROP_OUT_OF_RESOURCES;

View File

@ -2548,6 +2548,31 @@ struct gl_renderbuffer
struct gl_renderbuffer *rb,
GLenum internalFormat,
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 gl_framebuffer *fb = st->ctx->DrawBuffer;
struct st_renderbuffer *strb;
struct gl_renderbuffer *rb;
GLuint i;
st_flush_bitmap_cache(st);
@ -142,23 +142,23 @@ st_update_framebuffer_state( struct st_context *st )
for (i = 0; i < fb->_NumColorDrawBuffers; i++) {
framebuffer.cbufs[i] = NULL;
strb = st_renderbuffer(fb->_ColorDrawBuffers[i]);
rb = fb->_ColorDrawBuffers[i];
if (strb) {
if (strb->is_rtt || (strb->texture &&
_mesa_is_format_srgb(strb->Base.Format))) {
if (rb) {
if (rb->is_rtt || (rb->texture &&
_mesa_is_format_srgb(rb->Format))) {
/* 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 (strb->surface->context != st->pipe) {
st_regen_renderbuffer_surface(st, strb);
if (rb->surface) {
if (rb->surface->context != st->pipe) {
st_regen_renderbuffer_surface(st, rb);
}
framebuffer.cbufs[i] = strb->surface;
update_framebuffer_size(&framebuffer, strb->surface);
framebuffer.cbufs[i] = rb->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.
*/
strb = st_renderbuffer(fb->Attachment[BUFFER_DEPTH].Renderbuffer);
if (!strb)
strb = st_renderbuffer(fb->Attachment[BUFFER_STENCIL].Renderbuffer);
rb = fb->Attachment[BUFFER_DEPTH].Renderbuffer;
if (!rb)
rb = fb->Attachment[BUFFER_STENCIL].Renderbuffer;
if (strb) {
if (strb->is_rtt) {
if (rb) {
if (rb->is_rtt) {
/* 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) {
st_regen_renderbuffer_surface(st, strb);
if (rb->surface && rb->surface->context != st->pipe) {
st_regen_renderbuffer_surface(st, rb);
}
framebuffer.zsbuf = strb->surface;
if (strb->surface)
update_framebuffer_size(&framebuffer, strb->surface);
framebuffer.zsbuf = rb->surface;
if (rb->surface)
update_framebuffer_size(&framebuffer, rb->surface);
}
else
framebuffer.zsbuf = NULL;

View File

@ -202,8 +202,7 @@ st_BlitFramebuffer(struct gl_context *ctx,
blit.src.format = util_format_linear(blit.src.format);
}
else {
struct st_renderbuffer *srcRb =
st_renderbuffer(readFB->_ColorReadBuffer);
struct gl_renderbuffer *srcRb = readFB->_ColorReadBuffer;
struct pipe_surface *srcSurf;
if (!srcRb)
@ -223,8 +222,7 @@ st_BlitFramebuffer(struct gl_context *ctx,
}
for (i = 0; i < drawFB->_NumColorDrawBuffers; i++) {
struct st_renderbuffer *dstRb =
st_renderbuffer(drawFB->_ColorDrawBuffers[i]);
struct gl_renderbuffer *dstRb = drawFB->_ColorDrawBuffers[i];
if (dstRb) {
struct pipe_surface *dstSurf;
@ -250,17 +248,17 @@ st_BlitFramebuffer(struct gl_context *ctx,
/* depth and/or stencil blit */
/* get src/dst depth surfaces */
struct st_renderbuffer *srcDepthRb =
st_renderbuffer(readFB->Attachment[BUFFER_DEPTH].Renderbuffer);
struct st_renderbuffer *dstDepthRb =
st_renderbuffer(drawFB->Attachment[BUFFER_DEPTH].Renderbuffer);
struct gl_renderbuffer *srcDepthRb =
readFB->Attachment[BUFFER_DEPTH].Renderbuffer;
struct gl_renderbuffer *dstDepthRb =
drawFB->Attachment[BUFFER_DEPTH].Renderbuffer;
struct pipe_surface *dstDepthSurf =
dstDepthRb ? dstDepthRb->surface : NULL;
struct st_renderbuffer *srcStencilRb =
st_renderbuffer(readFB->Attachment[BUFFER_STENCIL].Renderbuffer);
struct st_renderbuffer *dstStencilRb =
st_renderbuffer(drawFB->Attachment[BUFFER_STENCIL].Renderbuffer);
struct gl_renderbuffer *srcStencilRb =
readFB->Attachment[BUFFER_STENCIL].Renderbuffer;
struct gl_renderbuffer *dstStencilRb =
drawFB->Attachment[BUFFER_STENCIL].Renderbuffer;
struct pipe_surface *dstStencilSurf =
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)) {
struct gl_renderbuffer *rb
= ctx->DrawBuffer->Attachment[b].Renderbuffer;
struct st_renderbuffer *strb = st_renderbuffer(rb);
int colormask_index = ctx->Extensions.EXT_draw_buffers2 ? i : 0;
if (!strb || !strb->surface)
if (!rb || !rb->surface)
continue;
unsigned colormask =
@ -458,7 +457,7 @@ st_Clear(struct gl_context *ctx, GLbitfield mask)
continue;
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);
if ((scissor && !st->can_scissor_clear) ||
@ -473,9 +472,7 @@ st_Clear(struct gl_context *ctx, GLbitfield mask)
}
if (mask & BUFFER_BIT_DEPTH) {
struct st_renderbuffer *strb = st_renderbuffer(depthRb);
if (strb->surface && ctx->Depth.Mask) {
if (depthRb->surface && ctx->Depth.Mask) {
bool scissor = is_scissor_enabled(ctx, depthRb);
if ((scissor && !st->can_scissor_clear) ||
is_window_rectangle_enabled(ctx))
@ -486,9 +483,7 @@ st_Clear(struct gl_context *ctx, GLbitfield mask)
}
}
if (mask & BUFFER_BIT_STENCIL) {
struct st_renderbuffer *strb = st_renderbuffer(stencilRb);
if (strb->surface && !is_stencil_disabled(ctx, stencilRb)) {
if (stencilRb->surface && !is_stencil_disabled(ctx, stencilRb)) {
bool scissor = is_scissor_enabled(ctx, stencilRb);
if ((scissor && !st->can_scissor_clear) ||
is_window_rectangle_enabled(ctx) ||

View File

@ -655,8 +655,7 @@ st_CopyImageSubData(struct gl_context *ctx,
src_z += src_image->TexObject->Attrib.MinLayer;
}
} else {
struct st_renderbuffer *src = st_renderbuffer(src_renderbuffer);
src_res = src->texture;
src_res = src_renderbuffer->texture;
src_level = 0;
}
@ -671,8 +670,7 @@ st_CopyImageSubData(struct gl_context *ctx,
dst_z += dst_image->TexObject->Attrib.MinLayer;
}
} else {
struct st_renderbuffer *dst = st_renderbuffer(dst_renderbuffer);
dst_res = dst->texture;
dst_res = dst_renderbuffer->texture;
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 pipe_context *pipe = st->pipe;
struct st_renderbuffer *strb;
struct gl_renderbuffer *rb;
enum pipe_map_flags usage;
struct pipe_transfer *pt;
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;
GLuint *zValues;
strb = st_renderbuffer(ctx->DrawBuffer->
Attachment[BUFFER_STENCIL].Renderbuffer);
rb = ctx->DrawBuffer->Attachment[BUFFER_STENCIL].Renderbuffer;
if (st_fb_orientation(ctx->DrawBuffer) == Y_0_TOP) {
y = ctx->DrawBuffer->Height - y - height;
}
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 */
usage = PIPE_MAP_READ_WRITE;
}
@ -989,9 +988,9 @@ draw_stencil_pixels(struct gl_context *ctx, GLint x, GLint y,
usage = PIPE_MAP_WRITE;
}
stmap = pipe_texture_map(pipe, strb->texture,
strb->surface->u.tex.level,
strb->surface->u.tex.first_layer,
stmap = pipe_texture_map(pipe, rb->texture,
rb->surface->u.tex.level,
rb->surface->u.tex.first_layer,
usage, x, y,
width, height, &pt);
@ -1418,7 +1417,7 @@ copy_stencil_pixels(struct gl_context *ctx, GLint srcx, GLint srcy,
GLsizei width, GLsizei height,
GLint dstx, GLint dsty)
{
struct st_renderbuffer *rbDraw;
struct gl_renderbuffer *rbDraw;
struct pipe_context *pipe = st_context(ctx)->pipe;
enum pipe_map_flags usage;
struct pipe_transfer *ptDraw;
@ -1433,8 +1432,7 @@ copy_stencil_pixels(struct gl_context *ctx, GLint srcx, GLint srcy,
}
/* Get the dest renderbuffer */
rbDraw = st_renderbuffer(ctx->DrawBuffer->
Attachment[BUFFER_STENCIL].Renderbuffer);
rbDraw = ctx->DrawBuffer->Attachment[BUFFER_STENCIL].Renderbuffer;
/* this will do stencil pixel transfer ops */
_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;
else
usage = PIPE_MAP_WRITE;
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);
@ -1489,7 +1487,7 @@ copy_stencil_pixels(struct gl_context *ctx, GLint srcx, GLint srcy,
dst = drawMap + y * ptDraw->stride;
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);
@ -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
*/
static struct st_renderbuffer *
static struct gl_renderbuffer *
st_get_color_read_renderbuffer(struct gl_context *ctx)
{
struct gl_framebuffer *fb = ctx->ReadBuffer;
struct st_renderbuffer *strb =
st_renderbuffer(fb->_ColorReadBuffer);
return strb;
return fb->_ColorReadBuffer;
}
@ -1554,7 +1549,7 @@ blit_copy_pixels(struct gl_context *ctx, GLint srcx, GLint srcy,
!_mesa_ati_fragment_shader_enabled(ctx) &&
ctx->DrawBuffer->_NumColorDrawBuffers == 1)) &&
!ctx->Query.CurrentOcclusionObject) {
struct st_renderbuffer *rbRead, *rbDraw;
struct gl_renderbuffer *rbRead, *rbDraw;
/*
* 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) {
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) {
rbRead = st_renderbuffer(ctx->ReadBuffer->Attachment[BUFFER_DEPTH].Renderbuffer);
rbDraw = st_renderbuffer(ctx->DrawBuffer->Attachment[BUFFER_DEPTH].Renderbuffer);
rbRead = ctx->ReadBuffer->Attachment[BUFFER_DEPTH].Renderbuffer;
rbDraw = ctx->DrawBuffer->Attachment[BUFFER_DEPTH].Renderbuffer;
} else if (type == GL_STENCIL) {
rbRead = st_renderbuffer(ctx->ReadBuffer->Attachment[BUFFER_STENCIL].Renderbuffer);
rbDraw = st_renderbuffer(ctx->DrawBuffer->Attachment[BUFFER_STENCIL].Renderbuffer);
rbRead = ctx->ReadBuffer->Attachment[BUFFER_STENCIL].Renderbuffer;
rbDraw = ctx->DrawBuffer->Attachment[BUFFER_STENCIL].Renderbuffer;
} else {
return false;
}
/* Flip src/dst position depending on the orientation of buffers. */
if (st_fb_orientation(ctx->ReadBuffer) == Y_0_TOP) {
readY = rbRead->Base.Height - readY;
readY = rbRead->Height - readY;
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
* its position and flip the source.
*/
drawY = rbDraw->Base.Height - drawY - drawH;
drawY = rbDraw->Height - drawY - drawH;
readY += 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 pipe_context *pipe = st->pipe;
struct pipe_screen *screen = st->screen;
struct st_renderbuffer *rbRead;
struct gl_renderbuffer *rbRead;
void *driver_fp;
struct pipe_resource *pt;
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);
} else if (type == GL_DEPTH) {
rbRead = st_renderbuffer(ctx->ReadBuffer->
Attachment[BUFFER_DEPTH].Renderbuffer);
rbRead = ctx->ReadBuffer->Attachment[BUFFER_DEPTH].Renderbuffer;
driver_fp = get_drawpix_z_stencil_program(st, GL_TRUE, GL_FALSE);
} else if (type == GL_STENCIL) {
rbRead = st_renderbuffer(ctx->ReadBuffer->
Attachment[BUFFER_STENCIL].Renderbuffer);
rbRead = ctx->ReadBuffer->Attachment[BUFFER_STENCIL].Renderbuffer;
driver_fp = get_drawpix_z_stencil_program(st, GL_FALSE, GL_TRUE);
} else if (type == GL_DEPTH_STENCIL) {
rbRead = st_renderbuffer(ctx->ReadBuffer->
Attachment[BUFFER_DEPTH].Renderbuffer);
rbRead = ctx->ReadBuffer->Attachment[BUFFER_DEPTH].Renderbuffer;
driver_fp = get_drawpix_z_stencil_program(st, GL_TRUE, GL_TRUE);
} else {
assert(type == GL_DEPTH_STENCIL_TO_RGBA_NV || type == GL_DEPTH_STENCIL_TO_BGRA_NV);
rbRead = st_renderbuffer(ctx->ReadBuffer->
Attachment[BUFFER_DEPTH].Renderbuffer);
rbRead = ctx->ReadBuffer->Attachment[BUFFER_DEPTH].Renderbuffer;
if (type == GL_DEPTH_STENCIL_TO_RGBA_NV)
driver_fp = get_drawpix_zs_to_color_program(st, GL_TRUE);
else

View File

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

View File

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

View File

@ -39,50 +39,10 @@
struct dd_function_table;
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 *
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
st_update_renderbuffer_surface(struct st_context *st,
struct st_renderbuffer *strb);
struct gl_renderbuffer *strb);
extern void
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);
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
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,
GLint x, GLint y, GLsizei width, GLsizei height,
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_screen *screen = st->screen;
struct cso_context *cso = st->cso_context;
struct pipe_surface *surface = strb->surface;
struct pipe_resource *texture = strb->texture;
struct pipe_surface *surface = rb->surface;
struct pipe_resource *texture = rb->texture;
const struct util_format_description *desc;
struct st_pbo_addresses addr;
struct pipe_framebuffer_state fb;
@ -273,7 +273,7 @@ fail:
* Create a staging texture and blit the requested region to it.
*/
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,
GLint x, GLint y, GLsizei width, GLsizei height,
GLenum format,
@ -310,8 +310,8 @@ blit_to_staging(struct st_context *st, struct st_renderbuffer *strb,
return NULL;
memset(&blit, 0, sizeof(blit));
blit.src.resource = strb->texture;
blit.src.level = strb->surface->u.tex.level;
blit.src.resource = rb->texture;
blit.src.level = rb->surface->u.tex.level;
blit.src.format = src_format;
blit.dst.resource = dst;
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.src.box.y = y;
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.src.box.width = blit.dst.box.width = width;
blit.src.box.height = blit.dst.box.height = height;
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.scissor_enable = FALSE;
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;
}
@ -341,13 +341,13 @@ blit_to_staging(struct st_context *st, struct st_renderbuffer *strb,
}
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,
GLsizei width, GLsizei height,
GLenum 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;
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. */
if (st->readpix_cache.src != src ||
st->readpix_cache.dst_format != dst_format ||
st->readpix_cache.level != strb->surface->u.tex.level ||
st->readpix_cache.layer != strb->surface->u.tex.first_layer) {
st->readpix_cache.level != rb->surface->u.tex.level ||
st->readpix_cache.layer != rb->surface->u.tex.first_layer) {
pipe_resource_reference(&st->readpix_cache.src, src);
pipe_resource_reference(&st->readpix_cache.cache, NULL);
st->readpix_cache.dst_format = dst_format;
st->readpix_cache.level = strb->surface->u.tex.level;
st->readpix_cache.layer = strb->surface->u.tex.first_layer;
st->readpix_cache.level = rb->surface->u.tex.level;
st->readpix_cache.layer = rb->surface->u.tex.first_layer;
st->readpix_cache.hits = 0;
}
/* Decide whether to trigger the 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
* 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) {
st->readpix_cache.hits += width * height;
return NULL;
}
strb->use_readpix_cache = true;
rb->use_readpix_cache = true;
}
/* 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,
strb->Base.Width,
strb->Base.Height, format,
rb->Width,
rb->Height, 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 gl_renderbuffer *rb =
_mesa_get_read_renderbuffer_for_format(ctx, format);
struct st_renderbuffer *strb = st_renderbuffer(rb);
struct pipe_context *pipe = st->pipe;
struct pipe_screen *screen = st->screen;
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. */
src = strb->texture;
src = rb->texture;
/* XXX Fallback for depth-stencil formats due to an incomplete
* 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
* 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_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 (try_pbo_readpixels(st, strb,
if (try_pbo_readpixels(st, rb,
st_fb_orientation(ctx->ReadBuffer) == Y_0_TOP,
x, y, width, height,
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
* synchronization overhead.
*/
dst = try_cached_readpixels(st, strb,
dst = try_cached_readpixels(st, rb,
st_fb_orientation(ctx->ReadBuffer) == Y_0_TOP,
width, height, format, src_format, dst_format);
if (dst) {
@ -515,7 +514,7 @@ st_ReadPixels(struct gl_context *ctx, GLint x, GLint y,
goto fallback;
}
dst = blit_to_staging(st, strb,
dst = blit_to_staging(st, rb,
st_fb_orientation(ctx->ReadBuffer) == Y_0_TOP,
x, y, width, height, format,
src_format, dst_format);

View File

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

View File

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

View File

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