diff options
Diffstat (limited to 'mesalib/src/mesa/drivers/common')
-rw-r--r-- | mesalib/src/mesa/drivers/common/driverfuncs.c | 4 | ||||
-rw-r--r-- | mesalib/src/mesa/drivers/common/meta.c | 42 | ||||
-rw-r--r-- | mesalib/src/mesa/drivers/common/meta.h | 32 | ||||
-rw-r--r-- | mesalib/src/mesa/drivers/common/meta_blit.c | 45 | ||||
-rw-r--r-- | mesalib/src/mesa/drivers/common/meta_copy_image.c | 3 | ||||
-rw-r--r-- | mesalib/src/mesa/drivers/common/meta_generate_mipmap.c | 8 | ||||
-rw-r--r-- | mesalib/src/mesa/drivers/common/meta_tex_subimage.c | 361 |
7 files changed, 447 insertions, 48 deletions
diff --git a/mesalib/src/mesa/drivers/common/driverfuncs.c b/mesalib/src/mesa/drivers/common/driverfuncs.c index 4f0f7a686..0d094ddf4 100644 --- a/mesalib/src/mesa/drivers/common/driverfuncs.c +++ b/mesalib/src/mesa/drivers/common/driverfuncs.c @@ -101,7 +101,7 @@ _mesa_init_driver_functions(struct dd_function_table *driver) driver->TestProxyTexImage = _mesa_test_proxy_teximage; driver->CompressedTexImage = _mesa_store_compressed_teximage; driver->CompressedTexSubImage = _mesa_store_compressed_texsubimage; - driver->GetCompressedTexImage = _mesa_get_compressed_teximage; + driver->GetCompressedTexImage = _mesa_GetCompressedTexImage_sw; driver->BindTexture = NULL; driver->NewTextureObject = _mesa_new_texture_object; driver->DeleteTexture = _mesa_delete_texture_object; @@ -210,7 +210,7 @@ _mesa_init_driver_functions(struct dd_function_table *driver) driver->EndCallList = NULL; /* GL_ARB_texture_storage */ - driver->AllocTextureStorage = _mesa_alloc_texture_storage; + driver->AllocTextureStorage = _mesa_AllocTextureStorage_sw; /* GL_ARB_texture_view */ driver->TextureView = NULL; diff --git a/mesalib/src/mesa/drivers/common/meta.c b/mesalib/src/mesa/drivers/common/meta.c index 87532c1df..3636ee83b 100644 --- a/mesalib/src/mesa/drivers/common/meta.c +++ b/mesalib/src/mesa/drivers/common/meta.c @@ -243,6 +243,7 @@ _mesa_meta_compile_and_link_program(struct gl_context *ctx, void _mesa_meta_setup_blit_shader(struct gl_context *ctx, GLenum target, + bool do_depth, struct blit_shader_table *table) { char *vs_source, *fs_source; @@ -292,10 +293,11 @@ _mesa_meta_setup_blit_shader(struct gl_context *ctx, "void main()\n" "{\n" " gl_FragColor = %s(texSampler, %s);\n" - " gl_FragDepth = gl_FragColor.x;\n" + "%s" "}\n", fs_preprocess, shader->type, fs_input, - shader->func, shader->texcoords); + shader->func, shader->texcoords, + do_depth ? " gl_FragDepth = gl_FragColor.x;\n" : ""); _mesa_meta_compile_and_link_program(ctx, vs_source, fs_source, ralloc_asprintf(mem_ctx, "%s blit", @@ -825,15 +827,18 @@ _mesa_meta_end(struct gl_context *ctx) const GLbitfield state = save->SavedState; int i; - /* After starting a new occlusion query, initialize the results to the - * values saved previously. The driver will then continue to increment - * these values. - */ + /* Grab the result of the old occlusion query before starting it again. The + * old result is added to the result of the new query so the driver will + * continue adding where it left off. */ if (state & MESA_META_OCCLUSION_QUERY) { if (save->CurrentOcclusionObject) { - _mesa_BeginQuery(save->CurrentOcclusionObject->Target, - save->CurrentOcclusionObject->Id); - ctx->Query.CurrentOcclusionObject->Result = save->CurrentOcclusionObject->Result; + struct gl_query_object *q = save->CurrentOcclusionObject; + GLuint64EXT result; + if (!q->Ready) + ctx->Driver.WaitQuery(ctx, q); + result = q->Result; + _mesa_BeginQuery(q->Target, q->Id); + ctx->Query.CurrentOcclusionObject->Result += result; } } @@ -1213,16 +1218,6 @@ _mesa_meta_end(struct gl_context *ctx) /** - * Determine whether Mesa is currently in a meta state. - */ -GLboolean -_mesa_meta_in_progress(struct gl_context *ctx) -{ - return ctx->Meta->SaveStackDepth != 0; -} - - -/** * Convert Z from a normalized value in the range [0, 1] to an object-space * Z coordinate in [-1, +1] so that drawing at the new Z position with the * default/identity ortho projection results in the original Z value. @@ -2801,7 +2796,8 @@ copytexsubimage_using_blit_framebuffer(struct gl_context *ctx, GLuint dims, * are too strict for CopyTexImage. We know meta will be fine with format * changes. */ - mask = _mesa_meta_BlitFramebuffer(ctx, x, y, + mask = _mesa_meta_BlitFramebuffer(ctx, ctx->ReadBuffer, ctx->DrawBuffer, + x, y, x + width, y + height, xoffset, yoffset, xoffset + width, yoffset + height, @@ -3045,7 +3041,7 @@ decompress_texture_image(struct gl_context *ctx, _mesa_meta_setup_vertex_objects(&decompress->VAO, &decompress->VBO, true, 2, 4, 0); - _mesa_meta_setup_blit_shader(ctx, target, &decompress->shaders); + _mesa_meta_setup_blit_shader(ctx, target, false, &decompress->shaders); } else { _mesa_meta_setup_ff_tnl_for_blit(&decompress->VAO, &decompress->VBO, 3); } @@ -3177,7 +3173,7 @@ _mesa_meta_GetTexImage(struct gl_context *ctx, { if (_mesa_is_format_compressed(texImage->TexFormat)) { GLuint slice; - bool result; + bool result = true; for (slice = 0; slice < texImage->Depth; slice++) { void *dst; @@ -3208,7 +3204,7 @@ _mesa_meta_GetTexImage(struct gl_context *ctx, return; } - _mesa_get_teximage(ctx, format, type, pixels, texImage); + _mesa_GetTexImage_sw(ctx, format, type, pixels, texImage); } diff --git a/mesalib/src/mesa/drivers/common/meta.h b/mesalib/src/mesa/drivers/common/meta.h index 6ecf3c005..e7d894df1 100644 --- a/mesalib/src/mesa/drivers/common/meta.h +++ b/mesalib/src/mesa/drivers/common/meta.h @@ -298,7 +298,8 @@ struct blit_state { GLuint VAO; GLuint VBO; - struct blit_shader_table shaders; + struct blit_shader_table shaders_with_depth; + struct blit_shader_table shaders_without_depth; GLuint msaa_shaders[BLIT_MSAA_SHADER_COUNT]; struct temp_texture depthTex; bool no_ctsi_fallback; @@ -446,8 +447,11 @@ _mesa_meta_begin(struct gl_context *ctx, GLbitfield state); extern void _mesa_meta_end(struct gl_context *ctx); -extern GLboolean -_mesa_meta_in_progress(struct gl_context *ctx); +static inline bool +_mesa_meta_in_progress(struct gl_context *ctx) +{ + return ctx->Meta->SaveStackDepth != 0; +} extern void _mesa_meta_fb_tex_blit_begin(const struct gl_context *ctx, @@ -471,12 +475,16 @@ _mesa_meta_setup_sampler(struct gl_context *ctx, extern GLbitfield _mesa_meta_BlitFramebuffer(struct gl_context *ctx, + const struct gl_framebuffer *readFb, + const struct gl_framebuffer *drawFb, GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter); extern void _mesa_meta_and_swrast_BlitFramebuffer(struct gl_context *ctx, + struct gl_framebuffer *readFb, + struct gl_framebuffer *drawFb, GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, @@ -519,6 +527,23 @@ extern void _mesa_meta_GenerateMipmap(struct gl_context *ctx, GLenum target, struct gl_texture_object *texObj); +extern bool +_mesa_meta_pbo_TexSubImage(struct gl_context *ctx, GLuint dims, + struct gl_texture_image *tex_image, + int xoffset, int yoffset, int zoffset, + int width, int height, int depth, + GLenum format, GLenum type, const void *pixels, + bool allocate_storage, bool create_pbo, + const struct gl_pixelstore_attrib *packing); + +extern bool +_mesa_meta_pbo_GetTexSubImage(struct gl_context *ctx, GLuint dims, + struct gl_texture_image *tex_image, + int xoffset, int yoffset, int zoffset, + int width, int height, int depth, + GLenum format, GLenum type, const void *pixels, + const struct gl_pixelstore_attrib *packing); + extern void _mesa_meta_CopyTexSubImage(struct gl_context *ctx, GLuint dims, struct gl_texture_image *texImage, @@ -612,6 +637,7 @@ _mesa_meta_setup_copypix_texture(struct gl_context *ctx, void _mesa_meta_setup_blit_shader(struct gl_context *ctx, GLenum target, + bool do_depth, struct blit_shader_table *table); void diff --git a/mesalib/src/mesa/drivers/common/meta_blit.c b/mesalib/src/mesa/drivers/common/meta_blit.c index 01cb532fe..3406be1ed 100644 --- a/mesalib/src/mesa/drivers/common/meta_blit.c +++ b/mesalib/src/mesa/drivers/common/meta_blit.c @@ -232,6 +232,7 @@ setup_glsl_msaa_blit_scaled_shader(struct gl_context *ctx, static void setup_glsl_msaa_blit_shader(struct gl_context *ctx, struct blit_state *blit, + const struct gl_framebuffer *drawFb, struct gl_renderbuffer *src_rb, GLenum target) { @@ -267,7 +268,7 @@ setup_glsl_msaa_blit_shader(struct gl_context *ctx, /* Update the assert if we plan to support more than 16X MSAA. */ assert(shader_offset >= 0 && shader_offset <= 4); - if (ctx->DrawBuffer->Visual.samples > 1) { + if (drawFb->Visual.samples > 1) { /* If you're calling meta_BlitFramebuffer with the destination * multisampled, this is the only path that will work -- swrast and * CopyTexImage won't work on it either. @@ -508,9 +509,11 @@ setup_glsl_msaa_blit_shader(struct gl_context *ctx, static void setup_glsl_blit_framebuffer(struct gl_context *ctx, struct blit_state *blit, + const struct gl_framebuffer *drawFb, struct gl_renderbuffer *src_rb, GLenum target, GLenum filter, - bool is_scaled_blit) + bool is_scaled_blit, + bool do_depth) { unsigned texcoord_size; bool is_target_multisample = target == GL_TEXTURE_2D_MULTISAMPLE || @@ -529,9 +532,11 @@ setup_glsl_blit_framebuffer(struct gl_context *ctx, if (is_target_multisample && is_filter_scaled_resolve && is_scaled_blit) { setup_glsl_msaa_blit_scaled_shader(ctx, blit, src_rb, target, filter); } else if (is_target_multisample) { - setup_glsl_msaa_blit_shader(ctx, blit, src_rb, target); + setup_glsl_msaa_blit_shader(ctx, blit, drawFb, src_rb, target); } else { - _mesa_meta_setup_blit_shader(ctx, target, &blit->shaders); + _mesa_meta_setup_blit_shader(ctx, target, do_depth, + do_depth ? &blit->shaders_with_depth + : &blit->shaders_without_depth); } } @@ -543,12 +548,13 @@ setup_glsl_blit_framebuffer(struct gl_context *ctx, */ static bool blitframebuffer_texture(struct gl_context *ctx, + const struct gl_framebuffer *readFb, + const struct gl_framebuffer *drawFb, GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLenum filter, GLint flipX, GLint flipY, GLboolean glsl_version, GLboolean do_depth) { - const struct gl_framebuffer *readFb = ctx->ReadBuffer; int att_index = do_depth ? BUFFER_DEPTH : readFb->_ColorReadBufferIndex; const struct gl_renderbuffer_attachment *readAtt = &readFb->Attachment[att_index]; @@ -642,7 +648,8 @@ blitframebuffer_texture(struct gl_context *ctx, scaled_blit = dstW != srcW || dstH != srcH; if (glsl_version) { - setup_glsl_blit_framebuffer(ctx, blit, rb, target, filter, scaled_blit); + setup_glsl_blit_framebuffer(ctx, blit, drawFb, rb, target, filter, scaled_blit, + do_depth); } else { _mesa_meta_setup_ff_tnl_for_blit(&ctx->Meta->Blit.VAO, @@ -677,7 +684,7 @@ blitframebuffer_texture(struct gl_context *ctx, */ if (ctx->Extensions.EXT_texture_sRGB_decode) { if (_mesa_get_format_color_encoding(rb->Format) == GL_SRGB && - ctx->DrawBuffer->Visual.sRGBCapable) { + drawFb->Visual.sRGBCapable) { _mesa_SamplerParameteri(fb_tex_blit.sampler, GL_TEXTURE_SRGB_DECODE_EXT, GL_DECODE_EXT); _mesa_set_framebuffer_srgb(ctx, GL_TRUE); @@ -701,7 +708,7 @@ blitframebuffer_texture(struct gl_context *ctx, if (target == GL_TEXTURE_2D) { const struct gl_texture_image *texImage - = _mesa_select_tex_image(ctx, texObj, target, srcLevel); + = _mesa_select_tex_image(texObj, target, srcLevel); s0 = srcX0 / (float) texImage->Width; s1 = srcX1 / (float) texImage->Width; t0 = srcY0 / (float) texImage->Height; @@ -869,6 +876,8 @@ _mesa_meta_setup_sampler(struct gl_context *ctx, */ GLbitfield _mesa_meta_BlitFramebuffer(struct gl_context *ctx, + const struct gl_framebuffer *readFb, + const struct gl_framebuffer *drawFb, GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter) @@ -890,7 +899,7 @@ _mesa_meta_BlitFramebuffer(struct gl_context *ctx, ctx->Extensions.ARB_fragment_shader; /* Multisample texture blit support requires texture multisample. */ - if (ctx->ReadBuffer->Visual.samples > 0 && + if (readFb->Visual.samples > 0 && !ctx->Extensions.ARB_texture_multisample) { return mask; } @@ -898,7 +907,8 @@ _mesa_meta_BlitFramebuffer(struct gl_context *ctx, /* Clip a copy of the blit coordinates. If these differ from the input * coordinates, then we'll set the scissor. */ - if (!_mesa_clip_blit(ctx, &clip.srcX0, &clip.srcY0, &clip.srcX1, &clip.srcY1, + if (!_mesa_clip_blit(ctx, readFb, drawFb, + &clip.srcX0, &clip.srcY0, &clip.srcX1, &clip.srcY1, &clip.dstX0, &clip.dstY0, &clip.dstX1, &clip.dstY1)) { /* clipped/scissored everything away */ return 0; @@ -926,7 +936,8 @@ _mesa_meta_BlitFramebuffer(struct gl_context *ctx, /* Try faster, direct texture approach first */ if (mask & GL_COLOR_BUFFER_BIT) { - if (blitframebuffer_texture(ctx, srcX0, srcY0, srcX1, srcY1, + if (blitframebuffer_texture(ctx, readFb, drawFb, + srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1, filter, dstFlipX, dstFlipY, use_glsl_version, false)) { @@ -935,7 +946,8 @@ _mesa_meta_BlitFramebuffer(struct gl_context *ctx, } if (mask & GL_DEPTH_BUFFER_BIT && use_glsl_version) { - if (blitframebuffer_texture(ctx, srcX0, srcY0, srcX1, srcY1, + if (blitframebuffer_texture(ctx, readFb, drawFb, + srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1, filter, dstFlipX, dstFlipY, use_glsl_version, true)) { @@ -962,7 +974,8 @@ _mesa_meta_glsl_blit_cleanup(struct blit_state *blit) blit->VBO = 0; } - _mesa_meta_blit_shader_table_cleanup(&blit->shaders); + _mesa_meta_blit_shader_table_cleanup(&blit->shaders_with_depth); + _mesa_meta_blit_shader_table_cleanup(&blit->shaders_without_depth); _mesa_DeleteTextures(1, &blit->depthTex.TexObj); blit->depthTex.TexObj = 0; @@ -970,20 +983,22 @@ _mesa_meta_glsl_blit_cleanup(struct blit_state *blit) void _mesa_meta_and_swrast_BlitFramebuffer(struct gl_context *ctx, + struct gl_framebuffer *readFb, + struct gl_framebuffer *drawFb, GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter) { - mask = _mesa_meta_BlitFramebuffer(ctx, + mask = _mesa_meta_BlitFramebuffer(ctx, readFb, drawFb, srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1, mask, filter); if (mask == 0x0) return; - _swrast_BlitFramebuffer(ctx, + _swrast_BlitFramebuffer(ctx, readFb, drawFb, srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1, mask, filter); diff --git a/mesalib/src/mesa/drivers/common/meta_copy_image.c b/mesalib/src/mesa/drivers/common/meta_copy_image.c index fc0cbaf1b..1729766f7 100644 --- a/mesalib/src/mesa/drivers/common/meta_copy_image.c +++ b/mesalib/src/mesa/drivers/common/meta_copy_image.c @@ -189,7 +189,8 @@ _mesa_meta_CopyImageSubData_uncompressed(struct gl_context *ctx, * We have already created views to ensure that the texture formats * match. */ - ctx->Driver.BlitFramebuffer(ctx, src_x, src_y, + ctx->Driver.BlitFramebuffer(ctx, ctx->ReadBuffer, ctx->DrawBuffer, + src_x, src_y, src_x + src_width, src_y + src_height, dst_x, dst_y, dst_x + src_width, dst_y + src_height, diff --git a/mesalib/src/mesa/drivers/common/meta_generate_mipmap.c b/mesalib/src/mesa/drivers/common/meta_generate_mipmap.c index 8ffd8da3b..c1b6d3c1f 100644 --- a/mesalib/src/mesa/drivers/common/meta_generate_mipmap.c +++ b/mesalib/src/mesa/drivers/common/meta_generate_mipmap.c @@ -71,7 +71,7 @@ fallback_required(struct gl_context *ctx, GLenum target, } srcLevel = texObj->BaseLevel; - baseImage = _mesa_select_tex_image(ctx, texObj, target, srcLevel); + baseImage = _mesa_select_tex_image(texObj, target, srcLevel); if (!baseImage) { _mesa_perf_debug(ctx, MESA_DEBUG_SEVERITY_HIGH, "glGenerateMipmap() couldn't find base teximage\n"); @@ -193,7 +193,7 @@ _mesa_meta_GenerateMipmap(struct gl_context *ctx, GLenum target, if (use_glsl_version) { _mesa_meta_setup_vertex_objects(&mipmap->VAO, &mipmap->VBO, true, 2, 4, 0); - _mesa_meta_setup_blit_shader(ctx, target, &mipmap->shaders); + _mesa_meta_setup_blit_shader(ctx, target, false, &mipmap->shaders); } else { _mesa_meta_setup_ff_tnl_for_blit(&mipmap->VAO, &mipmap->VBO, 3); _mesa_set_enable(ctx, target, GL_TRUE); @@ -265,7 +265,7 @@ _mesa_meta_GenerateMipmap(struct gl_context *ctx, GLenum target, GLsizei srcWidth, srcHeight, srcDepth; GLsizei dstWidth, dstHeight, dstDepth; - srcImage = _mesa_select_tex_image(ctx, texObj, faceTarget, srcLevel); + srcImage = _mesa_select_tex_image(texObj, faceTarget, srcLevel); assert(srcImage->Border == 0); /* src size */ @@ -304,7 +304,7 @@ _mesa_meta_GenerateMipmap(struct gl_context *ctx, GLenum target, */ break; } - dstImage = _mesa_select_tex_image(ctx, texObj, faceTarget, dstLevel); + dstImage = _mesa_select_tex_image(texObj, faceTarget, dstLevel); /* limit minification to src level */ _mesa_TexParameteri(target, GL_TEXTURE_MAX_LEVEL, srcLevel); diff --git a/mesalib/src/mesa/drivers/common/meta_tex_subimage.c b/mesalib/src/mesa/drivers/common/meta_tex_subimage.c new file mode 100644 index 000000000..68c8273fe --- /dev/null +++ b/mesalib/src/mesa/drivers/common/meta_tex_subimage.c @@ -0,0 +1,361 @@ +/* + * Mesa 3-D graphics library + * + * Copyright (C) 2015 Intel Corporation. All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR + * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Authors: + * Jason Ekstrand <jason.ekstrand@intel.com> + */ + +#include "bufferobj.h" +#include "buffers.h" +#include "fbobject.h" +#include "glformats.h" +#include "glheader.h" +#include "image.h" +#include "macros.h" +#include "meta.h" +#include "pbo.h" +#include "shaderapi.h" +#include "state.h" +#include "teximage.h" +#include "texobj.h" +#include "texstate.h" +#include "uniforms.h" +#include "varray.h" + +static struct gl_texture_image * +create_texture_for_pbo(struct gl_context *ctx, bool create_pbo, + GLenum pbo_target, int width, int height, int depth, + GLenum format, GLenum type, const void *pixels, + const struct gl_pixelstore_attrib *packing, + GLuint *tmp_pbo, GLuint *tmp_tex) +{ + uint32_t pbo_format; + GLenum internal_format; + unsigned row_stride; + struct gl_buffer_object *buffer_obj; + struct gl_texture_object *tex_obj; + struct gl_texture_image *tex_image; + bool read_only; + + if ((packing->ImageHeight != 0 && packing->ImageHeight != height) || + packing->SwapBytes || + packing->LsbFirst || + packing->Invert) + return NULL; + + pbo_format = _mesa_format_from_format_and_type(format, type); + if (_mesa_format_is_mesa_array_format(pbo_format)) + pbo_format = _mesa_format_from_array_format(pbo_format); + + if (!pbo_format || !ctx->TextureFormatSupported[pbo_format]) + return NULL; + + /* Account for SKIP_PIXELS, SKIP_ROWS, ALIGNMENT, and SKIP_IMAGES */ + pixels = _mesa_image_address3d(packing, pixels, + width, height, format, type, 0, 0, 0); + row_stride = _mesa_image_row_stride(packing, width, format, type); + + if (_mesa_is_bufferobj(packing->BufferObj)) { + *tmp_pbo = 0; + buffer_obj = packing->BufferObj; + } else { + assert(create_pbo); + + _mesa_GenBuffers(1, tmp_pbo); + + /* We are not doing this inside meta_begin/end. However, we know the + * client doesn't have the given target bound, so we can go ahead and + * squash it. We'll set it back when we're done. + */ + _mesa_BindBuffer(pbo_target, *tmp_pbo); + + _mesa_BufferData(pbo_target, row_stride * height, pixels, GL_STREAM_DRAW); + + buffer_obj = ctx->Unpack.BufferObj; + pixels = NULL; + + _mesa_BindBuffer(pbo_target, 0); + } + + _mesa_GenTextures(1, tmp_tex); + tex_obj = _mesa_lookup_texture(ctx, *tmp_tex); + tex_obj->Target = depth > 1 ? GL_TEXTURE_2D_ARRAY : GL_TEXTURE_2D; + tex_obj->Immutable = GL_TRUE; + _mesa_initialize_texture_object(ctx, tex_obj, *tmp_tex, GL_TEXTURE_2D); + + internal_format = _mesa_get_format_base_format(pbo_format); + + tex_image = _mesa_get_tex_image(ctx, tex_obj, tex_obj->Target, 0); + _mesa_init_teximage_fields(ctx, tex_image, width, height, depth, + 0, internal_format, pbo_format); + + read_only = pbo_target == GL_PIXEL_UNPACK_BUFFER; + if (!ctx->Driver.SetTextureStorageForBufferObject(ctx, tex_obj, + buffer_obj, + (intptr_t)pixels, + row_stride, + read_only)) { + _mesa_DeleteTextures(1, tmp_tex); + _mesa_DeleteBuffers(1, tmp_pbo); + return NULL; + } + + return tex_image; +} + +bool +_mesa_meta_pbo_TexSubImage(struct gl_context *ctx, GLuint dims, + struct gl_texture_image *tex_image, + int xoffset, int yoffset, int zoffset, + int width, int height, int depth, + GLenum format, GLenum type, const void *pixels, + bool allocate_storage, bool create_pbo, + const struct gl_pixelstore_attrib *packing) +{ + GLuint pbo = 0, pbo_tex = 0, fbos[2] = { 0, 0 }; + struct gl_texture_image *pbo_tex_image; + GLenum status; + bool success = false; + int z; + + /* XXX: This should probably be passed in from somewhere */ + const char *where = "_mesa_meta_pbo_TexSubImage"; + + if (!_mesa_is_bufferobj(packing->BufferObj) && !create_pbo) + return false; + + if (format == GL_DEPTH_COMPONENT || + format == GL_DEPTH_STENCIL || + format == GL_STENCIL_INDEX || + format == GL_COLOR_INDEX) + return false; + + if (ctx->_ImageTransferState) + return false; + + if (!_mesa_validate_pbo_access(dims, packing, width, height, depth, + format, type, INT_MAX, pixels)) { + _mesa_error(ctx, GL_INVALID_OPERATION, + "%s(out of bounds PBO access)", where); + return true; + } + + if (_mesa_check_disallowed_mapping(packing->BufferObj)) { + /* buffer is mapped - that's an error */ + _mesa_error(ctx, GL_INVALID_OPERATION, "%s(PBO is mapped)", where); + return true; + } + + pbo_tex_image = create_texture_for_pbo(ctx, create_pbo, + GL_PIXEL_UNPACK_BUFFER, + width, height, depth, + format, type, pixels, packing, + &pbo, &pbo_tex); + if (!pbo_tex_image) + return false; + + if (allocate_storage) + ctx->Driver.AllocTextureImageBuffer(ctx, tex_image); + + /* Only stash the current FBO */ + _mesa_meta_begin(ctx, 0); + + _mesa_GenFramebuffers(2, fbos); + _mesa_BindFramebuffer(GL_READ_FRAMEBUFFER, fbos[0]); + _mesa_BindFramebuffer(GL_DRAW_FRAMEBUFFER, fbos[1]); + + if (tex_image->TexObject->Target == GL_TEXTURE_1D_ARRAY) { + assert(depth == 1); + depth = height; + height = 1; + } + + _mesa_meta_bind_fbo_image(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, + pbo_tex_image, 0); + /* If this passes on the first layer it should pass on the others */ + status = _mesa_CheckFramebufferStatus(GL_READ_FRAMEBUFFER); + if (status != GL_FRAMEBUFFER_COMPLETE) + goto fail; + + _mesa_meta_bind_fbo_image(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, + tex_image, zoffset); + /* If this passes on the first layer it should pass on the others */ + status = _mesa_CheckFramebufferStatus(GL_DRAW_FRAMEBUFFER); + if (status != GL_FRAMEBUFFER_COMPLETE) + goto fail; + + _mesa_update_state(ctx); + + if (_mesa_meta_BlitFramebuffer(ctx, ctx->ReadBuffer, ctx->DrawBuffer, + 0, 0, width, height, + xoffset, yoffset, + xoffset + width, yoffset + height, + GL_COLOR_BUFFER_BIT, GL_NEAREST)) + goto fail; + + for (z = 1; z < depth; z++) { + _mesa_meta_bind_fbo_image(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, + pbo_tex_image, z); + _mesa_meta_bind_fbo_image(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, + tex_image, zoffset + z); + + _mesa_update_state(ctx); + + _mesa_meta_BlitFramebuffer(ctx, ctx->ReadBuffer, ctx->DrawBuffer, + 0, 0, width, height, + xoffset, yoffset, + xoffset + width, yoffset + height, + GL_COLOR_BUFFER_BIT, GL_NEAREST); + } + + success = true; + +fail: + _mesa_DeleteFramebuffers(2, fbos); + _mesa_DeleteTextures(1, &pbo_tex); + _mesa_DeleteBuffers(1, &pbo); + + _mesa_meta_end(ctx); + + return success; +} + +bool +_mesa_meta_pbo_GetTexSubImage(struct gl_context *ctx, GLuint dims, + struct gl_texture_image *tex_image, + int xoffset, int yoffset, int zoffset, + int width, int height, int depth, + GLenum format, GLenum type, const void *pixels, + const struct gl_pixelstore_attrib *packing) +{ + GLuint pbo = 0, pbo_tex = 0, fbos[2] = { 0, 0 }; + struct gl_texture_image *pbo_tex_image; + GLenum status; + bool success = false; + int z; + + /* XXX: This should probably be passed in from somewhere */ + const char *where = "_mesa_meta_pbo_GetTexSubImage"; + + if (!_mesa_is_bufferobj(packing->BufferObj)) + return false; + + if (format == GL_DEPTH_COMPONENT || + format == GL_DEPTH_STENCIL || + format == GL_STENCIL_INDEX || + format == GL_COLOR_INDEX) + return false; + + if (ctx->_ImageTransferState) + return false; + + if (!_mesa_validate_pbo_access(dims, packing, width, height, depth, + format, type, INT_MAX, pixels)) { + _mesa_error(ctx, GL_INVALID_OPERATION, + "%s(out of bounds PBO access)", where); + return true; + } + + if (_mesa_check_disallowed_mapping(packing->BufferObj)) { + /* buffer is mapped - that's an error */ + _mesa_error(ctx, GL_INVALID_OPERATION, "%s(PBO is mapped)", where); + return true; + } + + pbo_tex_image = create_texture_for_pbo(ctx, false, GL_PIXEL_PACK_BUFFER, + width, height, depth, + format, type, pixels, packing, + &pbo, &pbo_tex); + if (!pbo_tex_image) + return false; + + /* Only stash the current FBO */ + _mesa_meta_begin(ctx, 0); + + _mesa_GenFramebuffers(2, fbos); + + if (tex_image && tex_image->TexObject->Target == GL_TEXTURE_1D_ARRAY) { + assert(depth == 1); + depth = height; + height = 1; + } + + /* If we were given a texture, bind it to the read framebuffer. If not, + * we're doing a ReadPixels and we should just use whatever framebuffer + * the client has bound. + */ + if (tex_image) { + _mesa_BindFramebuffer(GL_READ_FRAMEBUFFER, fbos[0]); + _mesa_meta_bind_fbo_image(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, + tex_image, zoffset); + /* If this passes on the first layer it should pass on the others */ + status = _mesa_CheckFramebufferStatus(GL_READ_FRAMEBUFFER); + if (status != GL_FRAMEBUFFER_COMPLETE) + goto fail; + } else { + assert(depth == 1); + } + + _mesa_BindFramebuffer(GL_DRAW_FRAMEBUFFER, fbos[1]); + _mesa_meta_bind_fbo_image(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, + pbo_tex_image, 0); + /* If this passes on the first layer it should pass on the others */ + status = _mesa_CheckFramebufferStatus(GL_DRAW_FRAMEBUFFER); + if (status != GL_FRAMEBUFFER_COMPLETE) + goto fail; + + _mesa_update_state(ctx); + + if (_mesa_meta_BlitFramebuffer(ctx, ctx->ReadBuffer, ctx->DrawBuffer, + xoffset, yoffset, + xoffset + width, yoffset + height, + 0, 0, width, height, + GL_COLOR_BUFFER_BIT, GL_NEAREST)) + goto fail; + + for (z = 1; z < depth; z++) { + _mesa_meta_bind_fbo_image(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, + tex_image, zoffset + z); + _mesa_meta_bind_fbo_image(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, + pbo_tex_image, z); + + _mesa_update_state(ctx); + + _mesa_meta_BlitFramebuffer(ctx, ctx->ReadBuffer, ctx->DrawBuffer, + xoffset, yoffset, + xoffset + width, yoffset + height, + 0, 0, width, height, + GL_COLOR_BUFFER_BIT, GL_NEAREST); + } + + success = true; + +fail: + _mesa_DeleteFramebuffers(2, fbos); + _mesa_DeleteTextures(1, &pbo_tex); + _mesa_DeleteBuffers(1, &pbo); + + _mesa_meta_end(ctx); + + return success; +} |