Exemplo n.º 1
0
/**
 * Map a teximage in a mipmap tree.
 * \param row_stride  returns row stride in bytes
 * \param image_stride  returns image stride in bytes (for 3D textures).
 * \param image_offsets pointer to array of pixel offsets from the returned
 *	  pointer to each depth image
 * \return address of mapping
 */
GLubyte *
intel_miptree_image_map(struct intel_context * intel,
                        struct intel_mipmap_tree * mt,
                        GLuint face,
                        GLuint level,
                        GLuint * row_stride, GLuint * image_offsets)
{
    GLuint x, y;
    DBG("%s \n", __FUNCTION__);

    if (row_stride)
        *row_stride = mt->region->pitch * mt->cpp;

    if (mt->target == GL_TEXTURE_3D) {
        int i;

        for (i = 0; i < mt->level[level].depth; i++) {

            intel_miptree_get_image_offset(mt, level, face, i,
                                           &x, &y);
            image_offsets[i] = x + y * mt->region->pitch;
        }

        return intel_region_map(intel, mt->region);
    } else {
        assert(mt->level[level].depth == 1);
        intel_miptree_get_image_offset(mt, level, face, 0,
                                       &x, &y);
        image_offsets[0] = 0;

        return intel_region_map(intel, mt->region) +
               (x + y * mt->region->pitch) * mt->cpp;
    }
}
Exemplo n.º 2
0
/**
 * Prepare for softare rendering.  Map current read/draw framebuffers'
 * renderbuffes and all currently bound texture objects.
 *
 * Old note: Moved locking out to get reasonable span performance.
 */
void
intelSpanRenderStart(GLcontext * ctx)
{
   struct intel_context *intel = intel_context(ctx);
   GLuint i;

   intelFinish(&intel->ctx);
   LOCK_HARDWARE(intel);

#if 0
   /* Just map the framebuffer and all textures.  Bufmgr code will
    * take care of waiting on the necessary fences:
    */
   intel_region_map(intel->intelScreen, intel->front_region);
   intel_region_map(intel->intelScreen, intel->back_region);
   intel_region_map(intel->intelScreen, intel->intelScreen->depth_region);
#endif

   for (i = 0; i < ctx->Const.MaxTextureCoordUnits; i++) {
      if (ctx->Texture.Unit[i]._ReallyEnabled) {
         struct gl_texture_object *texObj = ctx->Texture.Unit[i]._Current;
         intel_tex_map_images(intel, intel_texture_object(texObj));
      }
   }

   intel_map_unmap_buffers(intel, GL_TRUE);
}
Exemplo n.º 3
0
/**
 * \param mode  bitmask of GL_MAP_READ_BIT, GL_MAP_WRITE_BIT
 */
static void
intel_tex_map_image_for_swrast(struct intel_context *intel,
			       struct intel_texture_image *intel_image,
			       GLbitfield mode)
{
   int level;
   int face;
   struct intel_mipmap_tree *mt;
   unsigned int x, y;

   if (!intel_image || !intel_image->mt)
      return;

   level = intel_image->base.Base.Level;
   face = intel_image->base.Base.Face;
   mt = intel_image->mt;

   for (int i = 0; i < mt->level[level].depth; i++)
      intel_miptree_slice_resolve_depth(intel, mt, level, i);

   if (mt->target == GL_TEXTURE_3D ||
       mt->target == GL_TEXTURE_2D_ARRAY ||
       mt->target == GL_TEXTURE_1D_ARRAY) {
      int i;

      /* ImageOffsets[] is only used for swrast's fetch_texel_3d, so we can't
       * share code with the normal path.
       */
      for (i = 0; i < mt->level[level].depth; i++) {
	 intel_miptree_get_image_offset(mt, level, i, &x, &y);
	 intel_image->base.ImageOffsets[i] = x + y * (mt->region->pitch /
                                                      mt->region->cpp);
      }

      DBG("%s \n", __FUNCTION__);

      intel_image->base.Map = intel_region_map(intel, mt->region, mode);
   } else {
      assert(intel_image->base.Base.Depth == 1);
      intel_miptree_get_image_offset(mt, level, face, &x, &y);

      DBG("%s: (%d,%d) -> (%d, %d)/%d\n",
	  __FUNCTION__, face, level, x, y, mt->region->pitch);

      intel_image->base.Map = intel_region_map(intel, mt->region, mode) +
	 x * mt->cpp + y * mt->region->pitch;
   }

   assert(mt->region->pitch % mt->region->cpp == 0);
   intel_image->base.RowStride = mt->region->pitch / mt->region->cpp;
}
Exemplo n.º 4
0
/**
 * Copy mipmap image between trees
 */
void
intel_miptree_image_copy(struct intel_context *intel,
                         struct intel_mipmap_tree *dst,
                         GLuint face, GLuint level,
                         struct intel_mipmap_tree *src)
{
    GLuint width = src->level[level].width;
    GLuint height = src->level[level].height;
    GLuint depth = src->level[level].depth;
    GLuint src_x, src_y, dst_x, dst_y;
    GLuint i;
    GLboolean success;

    if (dst->compressed) {
        GLuint align_w, align_h;

        intel_get_texture_alignment_unit(dst->internal_format,
                                         &align_w, &align_h);
        height = (height + 3) / 4;
        width = ALIGN(width, align_w);
    }

    intel_prepare_render(intel);

    for (i = 0; i < depth; i++) {
        intel_miptree_get_image_offset(src, level, face, i, &src_x, &src_y);
        intel_miptree_get_image_offset(dst, level, face, i, &dst_x, &dst_y);
        success = intel_region_copy(intel,
                                    dst->region, 0, dst_x, dst_y,
                                    src->region, 0, src_x, src_y,
                                    width, height, GL_FALSE,
                                    GL_COPY);
        if (!success) {
            GLubyte *src_ptr, *dst_ptr;

            src_ptr = intel_region_map(intel, src->region);
            dst_ptr = intel_region_map(intel, dst->region);

            _mesa_copy_rect(dst_ptr,
                            dst->cpp,
                            dst->region->pitch,
                            dst_x, dst_y, width, height,
                            src_ptr,
                            src->region->pitch,
                            src_x, src_y);
            intel_region_unmap(intel, src->region);
            intel_region_unmap(intel, dst->region);
        }
    }
}
Exemplo n.º 5
0
/**
 * Map a teximage in a mipmap tree.
 * \param row_stride  returns row stride in bytes
 * \param image_stride  returns image stride in bytes (for 3D textures).
 * \param image_offsets pointer to array of pixel offsets from the returned
 *	  pointer to each depth image
 * \return address of mapping
 */
GLubyte *
intel_miptree_image_map(struct intel_context * intel,
                        struct intel_mipmap_tree * mt,
                        GLuint face,
                        GLuint level,
                        GLuint * row_stride, GLuint * image_offsets)
{
   DBG("%s \n", __FUNCTION__);

   if (row_stride)
      *row_stride = mt->pitch * mt->cpp;

   if (mt->target == GL_TEXTURE_3D) {
      int i;

      for (i = 0; i < mt->level[level].depth; i++)
	 image_offsets[i] = mt->level[level].image_offset[i] / mt->cpp;
   } else {
      assert(mt->level[level].depth == 1);
      assert(mt->target == GL_TEXTURE_CUBE_MAP ||
	     mt->level[level].image_offset[0] == 0);
      image_offsets[0] = 0;
   }

   return (intel_region_map(intel, mt->region) +
           intel_miptree_image_offset(mt, face, level));
}
Exemplo n.º 6
0
/* Upload data to a rectangular sub-region.  Lots of choices how to do this:
 *
 * - memcpy by span to current destination
 * - upload data as new buffer and blit
 *
 * Currently always memcpy.
 */
void
intel_region_data(struct intel_context *intel,
                  struct intel_region *dst,
                  GLuint dst_offset,
                  GLuint dstx, GLuint dsty,
                  const void *src, GLuint src_pitch,
                  GLuint srcx, GLuint srcy, GLuint width, GLuint height)
{
   _DBG("%s\n", __FUNCTION__);

   if (intel == NULL)
      return;

   if (dst->pbo) {
      if (dstx == 0 &&
          dsty == 0 && width == dst->pitch && height == dst->height)
         intel_region_release_pbo(intel, dst);
      else
         intel_region_cow(intel, dst);
   }

   LOCK_HARDWARE(intel);
   _mesa_copy_rect(intel_region_map(intel, dst) + dst_offset,
                   dst->cpp,
                   dst->pitch,
                   dstx, dsty, width, height, src, src_pitch, srcx, srcy);

   intel_region_unmap(intel, dst);
   UNLOCK_HARDWARE(intel);
}
Exemplo n.º 7
0
static void
map_regions(GLcontext * ctx,
            struct intel_renderbuffer *depthRb,
            struct intel_renderbuffer *stencilRb)
{
   struct intel_context *intel = intel_context(ctx);
   if (depthRb && depthRb->region) {
      intel_region_map(intel->intelScreen, depthRb->region);
      depthRb->pfMap = depthRb->region->map;
      depthRb->pfPitch = depthRb->region->pitch;
   }
   if (stencilRb && stencilRb->region) {
      intel_region_map(intel->intelScreen, stencilRb->region);
      stencilRb->pfMap = stencilRb->region->map;
      stencilRb->pfPitch = stencilRb->region->pitch;
   }
}
Exemplo n.º 8
0
/**
 * Map a teximage in a mipmap tree.
 * \param row_stride  returns row stride in bytes
 * \param image_stride  returns image stride in bytes (for 3D textures).
 * \return address of mapping
 */
GLubyte *
intel_miptree_image_map(struct intel_context * intel,
                        struct intel_mipmap_tree * mt,
                        GLuint face,
                        GLuint level,
                        GLuint * row_stride, GLuint * image_offsets)
{
   DBG("%s \n", __FUNCTION__);

   if (row_stride)
      *row_stride = mt->pitch * mt->cpp;

   if (image_offsets)
      memcpy(image_offsets, mt->level[level].image_offset,
             mt->level[level].depth * sizeof(GLuint));

   return (intel_region_map(intel->intelScreen, mt->region) +
           intel_miptree_image_offset(mt, face, level));
}
Exemplo n.º 9
0
/**
 * Map or unmap all the renderbuffers which we may need during
 * software rendering.
 * XXX in the future, we could probably convey extra information to
 * reduce the number of mappings needed.  I.e. if doing a glReadPixels
 * from the depth buffer, we really only need one mapping.
 *
 * XXX Rewrite this function someday.
 * We can probably just loop over all the renderbuffer attachments,
 * map/unmap all of them, and not worry about the _ColorDrawBuffers
 * _ColorReadBuffer, _DepthBuffer or _StencilBuffer fields.
 */
static void
intel_map_unmap_buffers(struct intel_context *intel, GLboolean map)
{
   GLcontext *ctx = &intel->ctx;
   GLuint i, j;
   struct intel_renderbuffer *irb;

   /* color draw buffers */
   for (i = 0; i < ctx->Const.MaxDrawBuffers; i++) {
      for (j = 0; j < ctx->DrawBuffer->_NumColorDrawBuffers[i]; j++) {
         struct gl_renderbuffer *rb =
            ctx->DrawBuffer->_ColorDrawBuffers[i][j];
         irb = intel_renderbuffer(rb);
         if (irb) {
            /* this is a user-created intel_renderbuffer */
            if (irb->region) {
               if (map)
                  intel_region_map(intel->intelScreen, irb->region);
               else
                  intel_region_unmap(intel->intelScreen, irb->region);
            }
            irb->pfMap = irb->region->map;
            irb->pfPitch = irb->region->pitch;
         }
      }
   }

   /* check for render to textures */
   for (i = 0; i < BUFFER_COUNT; i++) {
      struct gl_renderbuffer_attachment *att =
         ctx->DrawBuffer->Attachment + i;
      struct gl_texture_object *tex = att->Texture;
      if (tex) {
         /* render to texture */
         ASSERT(att->Renderbuffer);
         if (map) {
            struct gl_texture_image *texImg;
            texImg = tex->Image[att->CubeMapFace][att->TextureLevel];
            intel_tex_map_images(intel, intel_texture_object(tex));
         }
         else {
            intel_tex_unmap_images(intel, intel_texture_object(tex));
         }
      }
   }

   /* color read buffers */
   irb = intel_renderbuffer(ctx->ReadBuffer->_ColorReadBuffer);
   if (irb && irb->region) {
      if (map)
         intel_region_map(intel->intelScreen, irb->region);
      else
         intel_region_unmap(intel->intelScreen, irb->region);
      irb->pfMap = irb->region->map;
      irb->pfPitch = irb->region->pitch;
   }

   /* Account for front/back color page flipping.
    * The span routines use the pfMap and pfPitch fields which will
    * swap the front/back region map/pitch if we're page flipped.
    * Do this after mapping, above, so the map field is valid.
    */
#if 0
   if (map && ctx->DrawBuffer->Name == 0) {
      struct intel_renderbuffer *irbFront
         = intel_get_renderbuffer(ctx->DrawBuffer, BUFFER_FRONT_LEFT);
      struct intel_renderbuffer *irbBack
         = intel_get_renderbuffer(ctx->DrawBuffer, BUFFER_BACK_LEFT);
      if (irbBack) {
         /* double buffered */
         if (intel->sarea->pf_current_page == 0) {
            irbFront->pfMap = irbFront->region->map;
            irbFront->pfPitch = irbFront->region->pitch;
            irbBack->pfMap = irbBack->region->map;
            irbBack->pfPitch = irbBack->region->pitch;
         }
         else {
            irbFront->pfMap = irbBack->region->map;
            irbFront->pfPitch = irbBack->region->pitch;
            irbBack->pfMap = irbFront->region->map;
            irbBack->pfPitch = irbFront->region->pitch;
         }
      }
   }
#endif

   /* depth buffer (Note wrapper!) */
   if (ctx->DrawBuffer->_DepthBuffer) {
      irb = intel_renderbuffer(ctx->DrawBuffer->_DepthBuffer->Wrapped);
      if (irb && irb->region && irb->Base.Name != 0) {
         if (map) {
            intel_region_map(intel->intelScreen, irb->region);
            irb->pfMap = irb->region->map;
            irb->pfPitch = irb->region->pitch;
         }
         else {
            intel_region_unmap(intel->intelScreen, irb->region);
            irb->pfMap = NULL;
            irb->pfPitch = 0;
         }
      }
   }

   /* stencil buffer (Note wrapper!) */
   if (ctx->DrawBuffer->_StencilBuffer) {
      irb = intel_renderbuffer(ctx->DrawBuffer->_StencilBuffer->Wrapped);
      if (irb && irb->region && irb->Base.Name != 0) {
         if (map) {
            intel_region_map(intel->intelScreen, irb->region);
            irb->pfMap = irb->region->map;
            irb->pfPitch = irb->region->pitch;
         }
         else {
            intel_region_unmap(intel->intelScreen, irb->region);
            irb->pfMap = NULL;
            irb->pfPitch = 0;
         }
      }
   }
}