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"); }
static void swr_resource_destroy(struct pipe_screen *p_screen, struct pipe_resource *pt) { struct swr_screen *screen = swr_screen(p_screen); struct swr_resource *spr = swr_resource(pt); struct pipe_context *pipe = screen->pipe; /* Only wait on fence if the resource is being used */ if (pipe && spr->status) { /* But, if there's no fence pending, submit one. * XXX: Remove once draw timestamps are implmented. */ if (!swr_is_fence_pending(screen->flush_fence)) swr_fence_submit(swr_context(pipe), screen->flush_fence); swr_fence_finish(p_screen, screen->flush_fence, 0); swr_resource_unused(pt); } /* * Free resource primary surface. If resource is display target, winsys * manages the buffer and will free it on displaytarget_destroy. */ if (spr->display_target) { /* display target */ struct sw_winsys *winsys = screen->winsys; winsys->displaytarget_destroy(winsys, spr->display_target); } else AlignedFree(spr->swr.pBaseAddress); AlignedFree(spr->secondary.pBaseAddress); FREE(spr); }
static void swr_resource_destroy(struct pipe_screen *p_screen, struct pipe_resource *pt) { struct swr_screen *screen = swr_screen(p_screen); struct swr_resource *spr = swr_resource(pt); struct pipe_context *pipe = screen->pipe; if (spr->display_target) { /* If resource is display target, winsys manages the buffer and will * free it on displaytarget_destroy. */ swr_fence_finish(p_screen, NULL, screen->flush_fence, 0); struct sw_winsys *winsys = screen->winsys; winsys->displaytarget_destroy(winsys, spr->display_target); } else { /* For regular resources, if the resource is being used, defer deletion * (use aligned-free) */ if (pipe && spr->status) { swr_resource_unused(pt); swr_fence_work_free(screen->flush_fence, spr->swr.pBaseAddress, true); swr_fence_work_free(screen->flush_fence, spr->secondary.pBaseAddress, true); } else { AlignedFree(spr->swr.pBaseAddress); AlignedFree(spr->secondary.pBaseAddress); } } FREE(spr); }
static void swr_flush_frontbuffer(struct pipe_screen *p_screen, struct pipe_resource *resource, unsigned level, unsigned layer, void *context_private, struct pipe_box *sub_box) { struct swr_screen *screen = swr_screen(p_screen); struct sw_winsys *winsys = screen->winsys; struct swr_resource *spr = swr_resource(resource); struct pipe_context *pipe = screen->pipe; if (pipe) { swr_fence_finish(p_screen, screen->flush_fence, 0); swr_resource_unused(resource); SwrEndFrame(swr_context(pipe)->swrContext); } debug_assert(spr->display_target); if (spr->display_target) winsys->displaytarget_display( winsys, spr->display_target, context_private, sub_box); }
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]); }
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]; }