Example #1
0
static void
swr_resource_copy(struct pipe_context *pipe,
                  struct pipe_resource *dst,
                  unsigned dst_level,
                  unsigned dstx,
                  unsigned dsty,
                  unsigned dstz,
                  struct pipe_resource *src,
                  unsigned src_level,
                  const struct pipe_box *src_box)
{
   struct swr_screen *screen = swr_screen(pipe->screen);

   /* If either the src or dst is a renderTarget, store tiles before copy */
   swr_store_dirty_resource(pipe, src, SWR_TILE_RESOLVED);
   swr_store_dirty_resource(pipe, dst, SWR_TILE_RESOLVED);

   swr_fence_finish(pipe->screen, NULL, screen->flush_fence, 0);
   swr_resource_unused(src);
   swr_resource_unused(dst);

   if ((dst->target == PIPE_BUFFER && src->target == PIPE_BUFFER)
       || (dst->target != PIPE_BUFFER && src->target != PIPE_BUFFER)) {
      util_resource_copy_region(
         pipe, dst, dst_level, dstx, dsty, dstz, src, src_level, src_box);
      return;
   }

   debug_printf("unhandled swr_resource_copy\n");
}
Example #2
0
static void
swr_surface_destroy(struct pipe_context *pipe, struct pipe_surface *surf)
{
   assert(surf->texture);
   struct pipe_resource *resource = surf->texture;

   /* If the resource has been drawn to, store tiles. */
   swr_store_dirty_resource(pipe, resource, SWR_TILE_RESOLVED);

   pipe_resource_reference(&resource, NULL);
   FREE(surf);
}
Example #3
0
static void
swr_flush(struct pipe_context *pipe,
          struct pipe_fence_handle **fence,
          unsigned flags)
{
   struct swr_context *ctx = swr_context(pipe);
   struct swr_screen *screen = swr_screen(pipe->screen);

   for (int i=0; i < ctx->framebuffer.nr_cbufs; i++) {
      struct pipe_surface *cb = ctx->framebuffer.cbufs[i];
      if (cb) {
         swr_store_dirty_resource(pipe, cb->texture, SWR_TILE_RESOLVED);
      }
   }
   if (ctx->framebuffer.zsbuf) {
      swr_store_dirty_resource(pipe, ctx->framebuffer.zsbuf->texture,
                               SWR_TILE_RESOLVED);
   }

   if (fence)
      swr_fence_reference(pipe->screen, fence, screen->flush_fence);
}
Example #4
0
static void
swr_flush(struct pipe_context *pipe,
          struct pipe_fence_handle **fence,
          unsigned flags)
{
   struct swr_context *ctx = swr_context(pipe);
   struct swr_screen *screen = swr_screen(pipe->screen);
   struct pipe_surface *cb = ctx->framebuffer.cbufs[0];

   /* If the current renderTarget is the display surface, store tiles back to
    * the surface, in preparation for present (swr_flush_frontbuffer).
    * Other renderTargets get stored back when attachment changes or
    * swr_surface_destroy */
   if (cb && swr_resource(cb->texture)->display_target)
      swr_store_dirty_resource(pipe, cb->texture, SWR_TILE_RESOLVED);

   if (fence)
      swr_fence_reference(pipe->screen, fence, screen->flush_fence);
}
Example #5
0
static void *
swr_transfer_map(struct pipe_context *pipe,
                 struct pipe_resource *resource,
                 unsigned level,
                 unsigned usage,
                 const struct pipe_box *box,
                 struct pipe_transfer **transfer)
{
   struct swr_screen *screen = swr_screen(pipe->screen);
   struct swr_resource *spr = swr_resource(resource);
   struct pipe_transfer *pt;
   enum pipe_format format = resource->format;

   assert(resource);
   assert(level <= resource->last_level);

   /* If mapping an attached rendertarget, store tiles to surface and set
    * postStoreTileState to SWR_TILE_INVALID so tiles get reloaded on next use
    * and nothing needs to be done at unmap. */
   swr_store_dirty_resource(pipe, resource, SWR_TILE_INVALID);

   if (!(usage & PIPE_TRANSFER_UNSYNCHRONIZED)) {
      /* If resource is in use, finish fence before mapping.
       * Unless requested not to block, then if not done return NULL map */
      if (usage & PIPE_TRANSFER_DONTBLOCK) {
         if (swr_is_fence_pending(screen->flush_fence))
            return NULL;
      } else {
         if (spr->status) {
            /* But, if there's no fence pending, submit one.
             * XXX: Remove once draw timestamps are finished. */
            if (!swr_is_fence_pending(screen->flush_fence))
               swr_fence_submit(swr_context(pipe), screen->flush_fence);

            swr_fence_finish(pipe->screen, NULL, screen->flush_fence, 0);
            swr_resource_unused(resource);
         }
      }
   }

   pt = CALLOC_STRUCT(pipe_transfer);
   if (!pt)
      return NULL;
   pipe_resource_reference(&pt->resource, resource);
   pt->usage = (pipe_transfer_usage)usage;
   pt->level = level;
   pt->box = *box;
   pt->stride = spr->swr.pitch;
   pt->layer_stride = spr->swr.qpitch * spr->swr.pitch;

   /* if we're mapping the depth/stencil, copy in stencil for the section
    * being read in
    */
   if (usage & PIPE_TRANSFER_READ && spr->has_depth && spr->has_stencil) {
      size_t zbase, sbase;
      for (int z = box->z; z < box->z + box->depth; z++) {
         zbase = (z * spr->swr.qpitch + box->y) * spr->swr.pitch +
            spr->mip_offsets[level];
         sbase = (z * spr->secondary.qpitch + box->y) * spr->secondary.pitch +
            spr->secondary_mip_offsets[level];
         for (int y = box->y; y < box->y + box->height; y++) {
            if (spr->base.format == PIPE_FORMAT_Z24_UNORM_S8_UINT) {
               for (int x = box->x; x < box->x + box->width; x++)
                  ((uint8_t*)(spr->swr.xpBaseAddress))[zbase + 4 * x + 3] =
                     ((uint8_t*)(spr->secondary.xpBaseAddress))[sbase + x];
            } else if (spr->base.format == PIPE_FORMAT_Z32_FLOAT_S8X24_UINT) {
               for (int x = box->x; x < box->x + box->width; x++)
                  ((uint8_t*)(spr->swr.xpBaseAddress))[zbase + 8 * x + 4] =
                     ((uint8_t*)(spr->secondary.xpBaseAddress))[sbase + x];
            }
            zbase += spr->swr.pitch;
            sbase += spr->secondary.pitch;
         }
      }
   }

   unsigned offset = box->z * pt->layer_stride +
      util_format_get_nblocksy(format, box->y) * pt->stride +
      util_format_get_stride(format, box->x);

   *transfer = pt;

   return (void*)(spr->swr.xpBaseAddress + offset + spr->mip_offsets[level]);
}
Example #6
0
static void
swr_blit(struct pipe_context *pipe, const struct pipe_blit_info *blit_info)
{
   struct swr_context *ctx = swr_context(pipe);
   /* Make a copy of the const blit_info, so we can modify it */
   struct pipe_blit_info info = *blit_info;

   if (info.render_condition_enable && !swr_check_render_cond(pipe))
      return;

   if (info.src.resource->nr_samples > 1 && info.dst.resource->nr_samples <= 1
       && !util_format_is_depth_or_stencil(info.src.resource->format)
       && !util_format_is_pure_integer(info.src.resource->format)) {
      debug_printf("swr_blit: color resolve : %d -> %d\n",
            info.src.resource->nr_samples, info.dst.resource->nr_samples);

      /* Resolve is done as part of the surface store. */
      swr_store_dirty_resource(pipe, info.src.resource, SWR_TILE_RESOLVED);

      struct pipe_resource *src_resource = info.src.resource;
      struct pipe_resource *resolve_target =
         swr_resource(src_resource)->resolve_target;

      /* The resolve target becomes the new source for the blit. */
      info.src.resource = resolve_target;
   }

   if (util_try_blit_via_copy_region(pipe, &info)) {
      return; /* done */
   }

   if (info.mask & PIPE_MASK_S) {
      debug_printf("swr: cannot blit stencil, skipping\n");
      info.mask &= ~PIPE_MASK_S;
   }

   if (!util_blitter_is_blit_supported(ctx->blitter, &info)) {
      debug_printf("swr: blit unsupported %s -> %s\n",
                   util_format_short_name(info.src.resource->format),
                   util_format_short_name(info.dst.resource->format));
      return;
   }

   if (ctx->active_queries) {
      ctx->api.pfnSwrEnableStatsFE(ctx->swrContext, FALSE);
      ctx->api.pfnSwrEnableStatsBE(ctx->swrContext, FALSE);
   }

   util_blitter_save_vertex_buffer_slot(ctx->blitter, ctx->vertex_buffer);
   util_blitter_save_vertex_elements(ctx->blitter, (void *)ctx->velems);
   util_blitter_save_vertex_shader(ctx->blitter, (void *)ctx->vs);
   util_blitter_save_geometry_shader(ctx->blitter, (void*)ctx->gs);
   util_blitter_save_so_targets(
      ctx->blitter,
      ctx->num_so_targets,
      (struct pipe_stream_output_target **)ctx->so_targets);
   util_blitter_save_rasterizer(ctx->blitter, (void *)ctx->rasterizer);
   util_blitter_save_viewport(ctx->blitter, &ctx->viewport);
   util_blitter_save_scissor(ctx->blitter, &ctx->scissor);
   util_blitter_save_fragment_shader(ctx->blitter, ctx->fs);
   util_blitter_save_blend(ctx->blitter, (void *)ctx->blend);
   util_blitter_save_depth_stencil_alpha(ctx->blitter,
                                         (void *)ctx->depth_stencil);
   util_blitter_save_stencil_ref(ctx->blitter, &ctx->stencil_ref);
   util_blitter_save_sample_mask(ctx->blitter, ctx->sample_mask);
   util_blitter_save_framebuffer(ctx->blitter, &ctx->framebuffer);
   util_blitter_save_fragment_sampler_states(
      ctx->blitter,
      ctx->num_samplers[PIPE_SHADER_FRAGMENT],
      (void **)ctx->samplers[PIPE_SHADER_FRAGMENT]);
   util_blitter_save_fragment_sampler_views(
      ctx->blitter,
      ctx->num_sampler_views[PIPE_SHADER_FRAGMENT],
      ctx->sampler_views[PIPE_SHADER_FRAGMENT]);
   util_blitter_save_render_condition(ctx->blitter,
                                      ctx->render_cond_query,
                                      ctx->render_cond_cond,
                                      ctx->render_cond_mode);

   util_blitter_blit(ctx->blitter, &info);

   if (ctx->active_queries) {
      ctx->api.pfnSwrEnableStatsFE(ctx->swrContext, TRUE);
      ctx->api.pfnSwrEnableStatsBE(ctx->swrContext, TRUE);
   }
}
Example #7
0
static void *
swr_transfer_map(struct pipe_context *pipe,
                 struct pipe_resource *resource,
                 unsigned level,
                 unsigned usage,
                 const struct pipe_box *box,
                 struct pipe_transfer **transfer)
{
   struct swr_screen *screen = swr_screen(pipe->screen);
   struct swr_resource *spr = swr_resource(resource);
   struct pipe_transfer *pt;
   enum pipe_format format = resource->format;

   assert(resource);
   assert(level <= resource->last_level);

   /* If mapping an attached rendertarget, store tiles to surface and set
    * postStoreTileState to SWR_TILE_INVALID so tiles get reloaded on next use
    * and nothing needs to be done at unmap. */
   swr_store_dirty_resource(pipe, resource, SWR_TILE_INVALID);

   if (!(usage & PIPE_TRANSFER_UNSYNCHRONIZED)) {
      /* If resource is in use, finish fence before mapping.
       * Unless requested not to block, then if not done return NULL map */
      if (usage & PIPE_TRANSFER_DONTBLOCK) {
         if (swr_is_fence_pending(screen->flush_fence))
            return NULL;
      } else {
         if (spr->status) {
            /* But, if there's no fence pending, submit one.
             * XXX: Remove once draw timestamps are finished. */
            if (!swr_is_fence_pending(screen->flush_fence))
               swr_fence_submit(swr_context(pipe), screen->flush_fence);

            swr_fence_finish(pipe->screen, screen->flush_fence, 0);
            swr_resource_unused(resource);
         }
      }
   }

   pt = CALLOC_STRUCT(pipe_transfer);
   if (!pt)
      return NULL;
   pipe_resource_reference(&pt->resource, resource);
   pt->level = level;
   pt->box = *box;
   pt->stride = spr->row_stride[level];
   pt->layer_stride = spr->img_stride[level];

   /* if we're mapping the depth/stencil, copy in stencil */
   if (spr->base.format == PIPE_FORMAT_Z24_UNORM_S8_UINT
       && spr->has_stencil) {
      for (unsigned i = 0; i < spr->alignedWidth * spr->alignedHeight; i++) {
         spr->swr.pBaseAddress[4 * i + 3] = spr->secondary.pBaseAddress[i];
      }
   } else if (spr->base.format == PIPE_FORMAT_Z32_FLOAT_S8X24_UINT
              && spr->has_stencil) {
      for (unsigned i = 0; i < spr->alignedWidth * spr->alignedHeight; i++) {
         spr->swr.pBaseAddress[8 * i + 4] = spr->secondary.pBaseAddress[i];
      }
   }

   unsigned offset = box->z * pt->layer_stride + box->y * pt->stride
      + box->x * util_format_get_blocksize(format);

   *transfer = pt;

   return spr->swr.pBaseAddress + offset + spr->mip_offsets[level];
}