/** * Build a struct pipe_blit_info object from the arguments used by the * pipe::resource_copy_region() function. */ static void build_blit_info(struct pipe_resource *dst_tex, unsigned dst_level, unsigned dst_x, unsigned dst_y, unsigned dst_z, struct pipe_resource *src_tex, unsigned src_level, const struct pipe_box *src_box, struct pipe_blit_info *blit) { memset(blit, 0, sizeof(*blit)); blit->src.format = src_tex->format; blit->dst.format = dst_tex->format; blit->mask = util_format_get_mask(blit->dst.format); blit->filter = PIPE_TEX_FILTER_NEAREST; blit->src.resource = src_tex; blit->src.level = src_level; blit->dst.resource = dst_tex; blit->dst.level = dst_level; blit->src.box = *src_box; u_box_3d(dst_x, dst_y, dst_z, src_box->width, src_box->height, src_box->depth, &blit->dst.box); }
static void i915_surface_copy_render(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 i915_context *i915 = i915_context(pipe); unsigned src_width0 = src->width0; unsigned src_height0 = src->height0; unsigned dst_width0 = dst->width0; unsigned dst_height0 = dst->height0; struct pipe_box dstbox; struct pipe_sampler_view src_templ, *src_view; struct pipe_surface dst_templ, *dst_view; const struct util_format_description *desc; /* Fallback for buffers. */ if (dst->target == PIPE_BUFFER && src->target == PIPE_BUFFER) goto fallback; /* Fallback for depth&stencil. XXX: see if we can use a proxy format */ desc = util_format_description(src->format); if (desc->colorspace == UTIL_FORMAT_COLORSPACE_ZS) goto fallback; desc = util_format_description(dst->format); if (desc->colorspace == UTIL_FORMAT_COLORSPACE_ZS) goto fallback; util_blitter_default_dst_texture(&dst_templ, dst, dst_level, dstz); util_blitter_default_src_texture(i915->blitter, &src_templ, src, src_level); if (!util_blitter_is_copy_supported(i915->blitter, dst, src)) goto fallback; i915_util_blitter_save_states(i915); dst_view = i915_create_surface_custom(pipe, dst, &dst_templ, dst_width0, dst_height0); src_view = i915_create_sampler_view_custom(pipe, src, &src_templ, src_width0, src_height0); u_box_3d(dstx, dsty, dstz, abs(src_box->width), abs(src_box->height), abs(src_box->depth), &dstbox); util_blitter_blit_generic(i915->blitter, dst_view, &dstbox, src_view, src_box, src_width0, src_height0, PIPE_MASK_RGBAZS, PIPE_TEX_FILTER_NEAREST, NULL, FALSE); return; fallback: util_resource_copy_region(pipe, dst, dst_level, dstx, dsty, dstz, src, src_level, src_box); }
/* Copy from a transfer's staging texture to a full GPU one. */ static void r600_copy_from_staging_texture(struct pipe_context *ctx, struct r600_transfer *rtransfer) { struct pipe_transfer *transfer = (struct pipe_transfer*)rtransfer; struct pipe_resource *texture = transfer->resource; struct pipe_box sbox; u_box_3d(0, 0, 0, transfer->box.width, transfer->box.height, transfer->box.depth, &sbox); ctx->resource_copy_region(ctx, texture, transfer->level, transfer->box.x, transfer->box.y, transfer->box.z, rtransfer->staging, 0, &sbox); }
HRESULT NINE_WINAPI NineVolume9_UnlockBox( struct NineVolume9 *This ) { DBG("This=%p lock_count=%u\n", This, This->lock_count); user_assert(This->lock_count, D3DERR_INVALIDCALL); if (This->transfer) { This->pipe->transfer_unmap(This->pipe, This->transfer); This->transfer = NULL; } --This->lock_count; if (This->data_conversion) { struct pipe_transfer *transfer; uint8_t *dst = This->data; struct pipe_box box; u_box_3d(0, 0, 0, This->desc.Width, This->desc.Height, This->desc.Depth, &box); if (!dst) { dst = This->pipe->transfer_map(This->pipe, This->resource, This->level, PIPE_TRANSFER_WRITE | PIPE_TRANSFER_DISCARD_WHOLE_RESOURCE, &box, &transfer); if (!dst) return D3D_OK; } (void) util_format_translate_3d(This->info.format, dst, This->data ? This->stride : transfer->stride, This->data ? This->layer_stride : transfer->layer_stride, 0, 0, 0, This->format_conversion, This->data_conversion, This->stride_conversion, This->layer_stride_conversion, 0, 0, 0, This->desc.Width, This->desc.Height, This->desc.Height); if (!This->data) pipe_transfer_unmap(This->pipe, transfer); } return D3D_OK; }
/* Copy a detiled texture to a tiled one. */ static void r300_copy_into_tiled_texture(struct pipe_context *ctx, struct r300_transfer *r300transfer) { struct pipe_transfer *transfer = (struct pipe_transfer*)r300transfer; struct pipe_resource *tex = transfer->resource; struct pipe_box src_box; u_box_3d(0, 0, 0, transfer->box.width, transfer->box.height, transfer->box.depth, &src_box); ctx->resource_copy_region(ctx, tex, transfer->level, transfer->box.x, transfer->box.y, transfer->box.z, &r300transfer->linear_texture->b.b, 0, &src_box); /* XXX remove this. */ r300_flush(ctx, 0, NULL); }
/* Copy from a transfer's staging texture to a full GPU one. */ static void r600_copy_from_staging_texture(struct pipe_context *ctx, struct r600_transfer *rtransfer) { struct r600_common_context *rctx = (struct r600_common_context*)ctx; struct pipe_transfer *transfer = (struct pipe_transfer*)rtransfer; struct pipe_resource *dst = transfer->resource; struct pipe_resource *src = &rtransfer->staging->b.b; struct pipe_box sbox; u_box_3d(0, 0, 0, transfer->box.width, transfer->box.height, transfer->box.depth, &sbox); if (dst->nr_samples > 1) { r600_copy_region_with_blit(ctx, dst, transfer->level, transfer->box.x, transfer->box.y, transfer->box.z, src, 0, &sbox); return; } rctx->dma_copy(ctx, dst, transfer->level, transfer->box.x, transfer->box.y, transfer->box.z, src, 0, &sbox); }
static void swr_transfer_unmap(struct pipe_context *pipe, struct pipe_transfer *transfer) { assert(transfer->resource); struct swr_resource *spr = swr_resource(transfer->resource); /* if we're mapping the depth/stencil, copy in stencil for the section * being written out */ if (transfer->usage & PIPE_TRANSFER_WRITE && !(transfer->usage & PIPE_TRANSFER_FLUSH_EXPLICIT) && spr->has_depth && spr->has_stencil) { struct pipe_box box; u_box_3d(0, 0, 0, transfer->box.width, transfer->box.height, transfer->box.depth, &box); swr_transfer_flush_region(pipe, transfer, &box); } pipe_resource_reference(&transfer->resource, NULL); FREE(transfer); }
inline void NineVolume9_AddDirtyRegion( struct NineVolume9 *This, const struct pipe_box *box ) { struct pipe_box cover_a, cover_b; float vol[2]; if (!box) { u_box_3d(0, 0, 0, This->desc.Width, This->desc.Height, This->desc.Depth, &This->dirty_box[0]); memset(&This->dirty_box[1], 0, sizeof(This->dirty_box[1])); return; } if (!This->dirty_box[0].width) { This->dirty_box[0] = *box; return; } u_box_union_3d(&cover_a, &This->dirty_box[0], box); vol[0] = u_box_volume_3d(&cover_a); if (This->dirty_box[1].width == 0) { vol[1] = u_box_volume_3d(&This->dirty_box[0]); if (vol[0] > (vol[1] * 1.5f)) This->dirty_box[1] = *box; else This->dirty_box[0] = cover_a; } else { u_box_union_3d(&cover_b, &This->dirty_box[1], box); vol[1] = u_box_volume_3d(&cover_b); if (vol[0] > vol[1]) This->dirty_box[1] = cover_b; else This->dirty_box[0] = cover_a; } }
static void r600_resource_copy_region(struct pipe_context *ctx, 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 r600_context *rctx = (struct r600_context *)ctx; struct pipe_surface *dst_view, dst_templ; struct pipe_sampler_view src_templ, *src_view; unsigned dst_width, dst_height, src_width0, src_height0, src_widthFL, src_heightFL; unsigned src_force_level = 0; struct pipe_box sbox, dstbox; /* Handle buffers first. */ if (dst->target == PIPE_BUFFER && src->target == PIPE_BUFFER) { if ((src->bind & PIPE_BIND_GLOBAL) || (dst->bind & PIPE_BIND_GLOBAL)) { r600_copy_global_buffer(ctx, dst, dstx, src, src_box); } else { r600_copy_buffer(ctx, dst, dstx, src, src_box); } return; } assert(u_max_sample(dst) == u_max_sample(src)); /* The driver doesn't decompress resources automatically while * u_blitter is rendering. */ if (!r600_decompress_subresource(ctx, src, src_level, src_box->z, src_box->z + src_box->depth - 1)) { return; /* error */ } dst_width = u_minify(dst->width0, dst_level); dst_height = u_minify(dst->height0, dst_level); src_width0 = src->width0; src_height0 = src->height0; src_widthFL = u_minify(src->width0, src_level); src_heightFL = u_minify(src->height0, src_level); util_blitter_default_dst_texture(&dst_templ, dst, dst_level, dstz); util_blitter_default_src_texture(&src_templ, src, src_level); if (util_format_is_compressed(src->format)) { unsigned blocksize = util_format_get_blocksize(src->format); if (blocksize == 8) src_templ.format = PIPE_FORMAT_R16G16B16A16_UINT; /* 64-bit block */ else src_templ.format = PIPE_FORMAT_R32G32B32A32_UINT; /* 128-bit block */ dst_templ.format = src_templ.format; dst_width = util_format_get_nblocksx(dst->format, dst_width); dst_height = util_format_get_nblocksy(dst->format, dst_height); src_width0 = util_format_get_nblocksx(src->format, src_width0); src_height0 = util_format_get_nblocksy(src->format, src_height0); src_widthFL = util_format_get_nblocksx(src->format, src_widthFL); src_heightFL = util_format_get_nblocksy(src->format, src_heightFL); dstx = util_format_get_nblocksx(dst->format, dstx); dsty = util_format_get_nblocksy(dst->format, dsty); sbox.x = util_format_get_nblocksx(src->format, src_box->x); sbox.y = util_format_get_nblocksy(src->format, src_box->y); sbox.z = src_box->z; sbox.width = util_format_get_nblocksx(src->format, src_box->width); sbox.height = util_format_get_nblocksy(src->format, src_box->height); sbox.depth = src_box->depth; src_box = &sbox; src_force_level = src_level; } else if (!util_blitter_is_copy_supported(rctx->blitter, dst, src)) { if (util_format_is_subsampled_422(src->format)) { src_templ.format = PIPE_FORMAT_R8G8B8A8_UINT; dst_templ.format = PIPE_FORMAT_R8G8B8A8_UINT; dst_width = util_format_get_nblocksx(dst->format, dst_width); src_width0 = util_format_get_nblocksx(src->format, src_width0); src_widthFL = util_format_get_nblocksx(src->format, src_widthFL); dstx = util_format_get_nblocksx(dst->format, dstx); sbox = *src_box; sbox.x = util_format_get_nblocksx(src->format, src_box->x); sbox.width = util_format_get_nblocksx(src->format, src_box->width); src_box = &sbox; } else { unsigned blocksize = util_format_get_blocksize(src->format); switch (blocksize) { case 1: dst_templ.format = PIPE_FORMAT_R8_UNORM; src_templ.format = PIPE_FORMAT_R8_UNORM; break; case 2: dst_templ.format = PIPE_FORMAT_R8G8_UNORM; src_templ.format = PIPE_FORMAT_R8G8_UNORM; break; case 4: dst_templ.format = PIPE_FORMAT_R8G8B8A8_UNORM; src_templ.format = PIPE_FORMAT_R8G8B8A8_UNORM; break; case 8: dst_templ.format = PIPE_FORMAT_R16G16B16A16_UINT; src_templ.format = PIPE_FORMAT_R16G16B16A16_UINT; break; case 16: dst_templ.format = PIPE_FORMAT_R32G32B32A32_UINT; src_templ.format = PIPE_FORMAT_R32G32B32A32_UINT; break; default: fprintf(stderr, "Unhandled format %s with blocksize %u\n", util_format_short_name(src->format), blocksize); assert(0); } } } dst_view = r600_create_surface_custom(ctx, dst, &dst_templ, dst_width, dst_height); if (rctx->b.chip_class >= EVERGREEN) { src_view = evergreen_create_sampler_view_custom(ctx, src, &src_templ, src_width0, src_height0, src_force_level); } else { src_view = r600_create_sampler_view_custom(ctx, src, &src_templ, src_widthFL, src_heightFL); } u_box_3d(dstx, dsty, dstz, abs(src_box->width), abs(src_box->height), abs(src_box->depth), &dstbox); /* Copy. */ r600_blitter_begin(ctx, R600_COPY_TEXTURE); util_blitter_blit_generic(rctx->blitter, dst_view, &dstbox, src_view, src_box, src_width0, src_height0, PIPE_MASK_RGBAZS, PIPE_TEX_FILTER_NEAREST, NULL); r600_blitter_end(ctx); pipe_surface_reference(&dst_view, NULL); pipe_sampler_view_reference(&src_view, NULL); }
/* Copy a block of pixels from one surface to another. */ static void r300_resource_copy_region(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 pipe_screen *screen = pipe->screen; struct r300_context *r300 = r300_context(pipe); struct pipe_framebuffer_state *fb = (struct pipe_framebuffer_state*)r300->fb_state.state; unsigned src_width0 = r300_resource(src)->tex.width0; unsigned src_height0 = r300_resource(src)->tex.height0; unsigned dst_width0 = r300_resource(dst)->tex.width0; unsigned dst_height0 = r300_resource(dst)->tex.height0; unsigned layout; struct pipe_box box, dstbox; struct pipe_sampler_view src_templ, *src_view; struct pipe_surface dst_templ, *dst_view; /* Fallback for buffers. */ if ((dst->target == PIPE_BUFFER && src->target == PIPE_BUFFER) || !r300_is_blit_supported(dst->format)) { util_resource_copy_region(pipe, dst, dst_level, dstx, dsty, dstz, src, src_level, src_box); return; } /* Can't read MSAA textures. */ if (src->nr_samples > 1 || dst->nr_samples > 1) { return; } /* The code below changes the texture format so that the copy can be done * on hardware. E.g. depth-stencil surfaces are copied as RGBA * colorbuffers. */ util_blitter_default_dst_texture(&dst_templ, dst, dst_level, dstz); util_blitter_default_src_texture(&src_templ, src, src_level); layout = util_format_description(dst_templ.format)->layout; /* Handle non-renderable plain formats. */ if (layout == UTIL_FORMAT_LAYOUT_PLAIN && (!screen->is_format_supported(screen, src_templ.format, src->target, src->nr_samples, PIPE_BIND_SAMPLER_VIEW) || !screen->is_format_supported(screen, dst_templ.format, dst->target, dst->nr_samples, PIPE_BIND_RENDER_TARGET))) { switch (util_format_get_blocksize(dst_templ.format)) { case 1: dst_templ.format = PIPE_FORMAT_I8_UNORM; break; case 2: dst_templ.format = PIPE_FORMAT_B4G4R4A4_UNORM; break; case 4: dst_templ.format = PIPE_FORMAT_B8G8R8A8_UNORM; break; case 8: dst_templ.format = PIPE_FORMAT_R16G16B16A16_UNORM; break; default: debug_printf("r300: copy_region: Unhandled format: %s. Falling back to software.\n" "r300: copy_region: Software fallback doesn't work for tiled textures.\n", util_format_short_name(dst_templ.format)); } src_templ.format = dst_templ.format; } /* Handle compressed formats. */ if (layout == UTIL_FORMAT_LAYOUT_S3TC || layout == UTIL_FORMAT_LAYOUT_RGTC) { assert(src_templ.format == dst_templ.format); box = *src_box; src_box = &box; dst_width0 = align(dst_width0, 4); dst_height0 = align(dst_height0, 4); src_width0 = align(src_width0, 4); src_height0 = align(src_height0, 4); box.width = align(box.width, 4); box.height = align(box.height, 4); switch (util_format_get_blocksize(dst_templ.format)) { case 8: /* one 4x4 pixel block has 8 bytes. * we set 1 pixel = 4 bytes ===> 1 block corrensponds to 2 pixels. */ dst_templ.format = PIPE_FORMAT_R8G8B8A8_UNORM; dst_width0 = dst_width0 / 2; src_width0 = src_width0 / 2; dstx /= 2; box.x /= 2; box.width /= 2; break; case 16: /* one 4x4 pixel block has 16 bytes. * we set 1 pixel = 4 bytes ===> 1 block corresponds to 4 pixels. */ dst_templ.format = PIPE_FORMAT_R8G8B8A8_UNORM; break; } src_templ.format = dst_templ.format; dst_height0 = dst_height0 / 4; src_height0 = src_height0 / 4; dsty /= 4; box.y /= 4; box.height /= 4; } /* Fallback for textures. */ if (!screen->is_format_supported(screen, dst_templ.format, dst->target, dst->nr_samples, PIPE_BIND_RENDER_TARGET) || !screen->is_format_supported(screen, src_templ.format, src->target, src->nr_samples, PIPE_BIND_SAMPLER_VIEW)) { assert(0 && "this shouldn't happen, update r300_is_blit_supported"); util_resource_copy_region(pipe, dst, dst_level, dstx, dsty, dstz, src, src_level, src_box); return; } /* Decompress ZMASK. */ if (r300->zmask_in_use && !r300->locked_zbuffer) { if (fb->zsbuf->texture == src || fb->zsbuf->texture == dst) { r300_decompress_zmask(r300); } } dst_view = r300_create_surface_custom(pipe, dst, &dst_templ, dst_width0, dst_height0); src_view = r300_create_sampler_view_custom(pipe, src, &src_templ, src_width0, src_height0); u_box_3d(dstx, dsty, dstz, abs(src_box->width), abs(src_box->height), abs(src_box->depth), &dstbox); r300_blitter_begin(r300, R300_COPY); util_blitter_blit_generic(r300->blitter, dst_view, &dstbox, src_view, src_box, src_width0, src_height0, PIPE_MASK_RGBAZS, PIPE_TEX_FILTER_NEAREST, NULL); r300_blitter_end(r300); pipe_surface_reference(&dst_view, NULL); pipe_sampler_view_reference(&src_view, NULL); }
HRESULT WINAPI NineVolume9_LockBox( struct NineVolume9 *This, D3DLOCKED_BOX *pLockedVolume, const D3DBOX *pBox, DWORD Flags ) { struct pipe_resource *resource = This->resource; struct pipe_box box; unsigned usage; DBG("This=%p(%p) pLockedVolume=%p pBox=%p[%u..%u,%u..%u,%u..%u] Flags=%s\n", This, This->base.container, pLockedVolume, pBox, pBox ? pBox->Left : 0, pBox ? pBox->Right : 0, pBox ? pBox->Top : 0, pBox ? pBox->Bottom : 0, pBox ? pBox->Front : 0, pBox ? pBox->Back : 0, nine_D3DLOCK_to_str(Flags)); user_assert(This->desc.Pool != D3DPOOL_DEFAULT || (This->desc.Usage & D3DUSAGE_DYNAMIC), D3DERR_INVALIDCALL); user_assert(!((Flags & D3DLOCK_DISCARD) && (Flags & D3DLOCK_READONLY)), D3DERR_INVALIDCALL); user_assert(This->lock_count == 0, D3DERR_INVALIDCALL); user_assert(pLockedVolume, E_POINTER); if (pBox && This->desc.Pool == D3DPOOL_DEFAULT && util_format_is_compressed(This->info.format)) { const unsigned w = util_format_get_blockwidth(This->info.format); const unsigned h = util_format_get_blockheight(This->info.format); user_assert(!(pBox->Left % w) && !(pBox->Right % w) && !(pBox->Top % h) && !(pBox->Bottom % h), D3DERR_INVALIDCALL); } if (Flags & D3DLOCK_DISCARD) { usage = PIPE_TRANSFER_WRITE | PIPE_TRANSFER_DISCARD_RANGE; } else { usage = (Flags & D3DLOCK_READONLY) ? PIPE_TRANSFER_READ : PIPE_TRANSFER_READ_WRITE; } if (Flags & D3DLOCK_DONOTWAIT) usage |= PIPE_TRANSFER_DONTBLOCK; if (pBox) { d3dbox_to_pipe_box(&box, pBox); if (u_box_clip_2d(&box, &box, This->desc.Width, This->desc.Height) < 0) { DBG("Locked volume intersection empty.\n"); return D3DERR_INVALIDCALL; } } else { u_box_3d(0, 0, 0, This->desc.Width, This->desc.Height, This->desc.Depth, &box); } if (This->data) { pLockedVolume->RowPitch = This->stride; pLockedVolume->SlicePitch = This->layer_stride; pLockedVolume->pBits = NineVolume9_GetSystemMemPointer(This, box.x, box.y, box.z); } else { pLockedVolume->pBits = This->pipe->transfer_map(This->pipe, resource, This->level, usage, &box, &This->transfer); if (!This->transfer) { if (Flags & D3DLOCK_DONOTWAIT) return D3DERR_WASSTILLDRAWING; return D3DERR_DRIVERINTERNALERROR; } pLockedVolume->RowPitch = This->transfer->stride; pLockedVolume->SlicePitch = This->transfer->layer_stride; } if (!(Flags & (D3DLOCK_NO_DIRTY_UPDATE | D3DLOCK_READONLY))) { NineVolume9_MarkContainerDirty(This); if (This->desc.Pool == D3DPOOL_MANAGED) NineVolume9_AddDirtyRegion(This, &box); } ++This->lock_count; return D3D_OK; }
static void si_resource_copy_region(struct pipe_context *ctx, 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 si_context *sctx = (struct si_context *)ctx; struct r600_texture *rdst = (struct r600_texture*)dst; struct pipe_surface *dst_view, dst_templ; struct pipe_sampler_view src_templ, *src_view; struct texture_orig_info orig_info[2]; struct pipe_box sbox, dstbox; boolean restore_orig[2]; /* Fallback for buffers. */ if (dst->target == PIPE_BUFFER && src->target == PIPE_BUFFER) { si_copy_buffer(sctx, dst, src, dstx, src_box->x, src_box->width); return; } memset(orig_info, 0, sizeof(orig_info)); /* The driver doesn't decompress resources automatically while * u_blitter is rendering. */ si_decompress_subresource(ctx, src, src_level, src_box->z, src_box->z + src_box->depth - 1); restore_orig[0] = restore_orig[1] = FALSE; if (util_format_is_compressed(src->format) && util_format_is_compressed(dst->format)) { si_compressed_to_blittable(src, src_level, &orig_info[0]); restore_orig[0] = TRUE; sbox.x = util_format_get_nblocksx(orig_info[0].format, src_box->x); sbox.y = util_format_get_nblocksy(orig_info[0].format, src_box->y); sbox.z = src_box->z; sbox.width = util_format_get_nblocksx(orig_info[0].format, src_box->width); sbox.height = util_format_get_nblocksy(orig_info[0].format, src_box->height); sbox.depth = src_box->depth; src_box = &sbox; si_compressed_to_blittable(dst, dst_level, &orig_info[1]); restore_orig[1] = TRUE; /* translate the dst box as well */ dstx = util_format_get_nblocksx(orig_info[1].format, dstx); dsty = util_format_get_nblocksy(orig_info[1].format, dsty); } else if (!util_blitter_is_copy_supported(sctx->blitter, dst, src)) { if (util_format_is_subsampled_422(src->format)) { /* XXX untested */ si_change_format(src, src_level, &orig_info[0], PIPE_FORMAT_R8G8B8A8_UINT); si_change_format(dst, dst_level, &orig_info[1], PIPE_FORMAT_R8G8B8A8_UINT); sbox = *src_box; sbox.x = util_format_get_nblocksx(orig_info[0].format, src_box->x); sbox.width = util_format_get_nblocksx(orig_info[0].format, src_box->width); src_box = &sbox; dstx = util_format_get_nblocksx(orig_info[1].format, dstx); restore_orig[0] = TRUE; restore_orig[1] = TRUE; } else { unsigned blocksize = util_format_get_blocksize(src->format); switch (blocksize) { case 1: si_change_format(src, src_level, &orig_info[0], PIPE_FORMAT_R8_UNORM); si_change_format(dst, dst_level, &orig_info[1], PIPE_FORMAT_R8_UNORM); break; case 2: si_change_format(src, src_level, &orig_info[0], PIPE_FORMAT_R8G8_UNORM); si_change_format(dst, dst_level, &orig_info[1], PIPE_FORMAT_R8G8_UNORM); break; case 4: si_change_format(src, src_level, &orig_info[0], PIPE_FORMAT_R8G8B8A8_UNORM); si_change_format(dst, dst_level, &orig_info[1], PIPE_FORMAT_R8G8B8A8_UNORM); break; case 8: si_change_format(src, src_level, &orig_info[0], PIPE_FORMAT_R16G16B16A16_UINT); si_change_format(dst, dst_level, &orig_info[1], PIPE_FORMAT_R16G16B16A16_UINT); break; case 16: si_change_format(src, src_level, &orig_info[0], PIPE_FORMAT_R32G32B32A32_UINT); si_change_format(dst, dst_level, &orig_info[1], PIPE_FORMAT_R32G32B32A32_UINT); break; default: fprintf(stderr, "Unhandled format %s with blocksize %u\n", util_format_short_name(src->format), blocksize); assert(0); } restore_orig[0] = TRUE; restore_orig[1] = TRUE; } } /* Initialize the surface. */ util_blitter_default_dst_texture(&dst_templ, dst, dst_level, dstz); dst_view = r600_create_surface_custom(ctx, dst, &dst_templ, rdst->surface.level[dst_level].npix_x, rdst->surface.level[dst_level].npix_y); /* Initialize the sampler view. */ util_blitter_default_src_texture(&src_templ, src, src_level); src_view = ctx->create_sampler_view(ctx, src, &src_templ); u_box_3d(dstx, dsty, dstz, abs(src_box->width), abs(src_box->height), abs(src_box->depth), &dstbox); /* Copy. */ si_blitter_begin(ctx, SI_COPY); util_blitter_blit_generic(sctx->blitter, dst_view, &dstbox, src_view, src_box, src->width0, src->height0, PIPE_MASK_RGBAZS, PIPE_TEX_FILTER_NEAREST, NULL); si_blitter_end(ctx); pipe_surface_reference(&dst_view, NULL); pipe_sampler_view_reference(&src_view, NULL); if (restore_orig[0]) si_reset_blittable_to_orig(src, src_level, &orig_info[0]); if (restore_orig[1]) si_reset_blittable_to_orig(dst, dst_level, &orig_info[1]); }
void r600_test_dma(struct r600_common_screen *rscreen) { struct pipe_screen *screen = &rscreen->b; struct pipe_context *ctx = screen->context_create(screen, NULL, 0); struct r600_common_context *rctx = (struct r600_common_context*)ctx; uint64_t max_alloc_size; unsigned i, iterations, num_partial_copies, max_levels, max_tex_side; unsigned num_pass = 0, num_fail = 0; max_levels = screen->get_param(screen, PIPE_CAP_MAX_TEXTURE_2D_LEVELS); max_tex_side = 1 << (max_levels - 1); /* Max 128 MB allowed for both textures. */ max_alloc_size = 128 * 1024 * 1024; /* the seed for random test parameters */ srand(0x9b47d95b); /* the seed for random pixel data */ s_rand_xorshift128plus(seed_xorshift128plus, false); iterations = 1000000000; /* just kill it when you are bored */ num_partial_copies = 30; /* These parameters are randomly generated per test: * - whether to do one whole-surface copy or N partial copies per test * - which tiling modes to use (LINEAR_ALIGNED, 1D, 2D) * - which texture dimensions to use * - whether to use VRAM (all tiling modes) and GTT (staging, linear * only) allocations * - random initial pixels in src * - generate random subrectangle copies for partial blits */ for (i = 0; i < iterations; i++) { struct pipe_resource tsrc = {}, tdst = {}, *src, *dst; struct r600_texture *rdst; struct r600_texture *rsrc; struct cpu_texture src_cpu, dst_cpu; unsigned bpp, max_width, max_height, max_depth, j, num; unsigned gfx_blits = 0, dma_blits = 0, max_tex_side_gen; unsigned max_tex_layers; bool pass; bool do_partial_copies = rand() & 1; /* generate a random test case */ tsrc.target = tdst.target = PIPE_TEXTURE_2D_ARRAY; tsrc.depth0 = tdst.depth0 = 1; bpp = 1 << (rand() % 5); tsrc.format = tdst.format = get_format_from_bpp(bpp); max_tex_side_gen = generate_max_tex_side(max_tex_side); max_tex_layers = rand() % 4 ? 1 : 5; tsrc.width0 = (rand() % max_tex_side_gen) + 1; tsrc.height0 = (rand() % max_tex_side_gen) + 1; tsrc.array_size = (rand() % max_tex_layers) + 1; /* Have a 1/4 chance of getting power-of-two dimensions. */ if (rand() % 4 == 0) { tsrc.width0 = util_next_power_of_two(tsrc.width0); tsrc.height0 = util_next_power_of_two(tsrc.height0); } if (!do_partial_copies) { /* whole-surface copies only, same dimensions */ tdst = tsrc; } else { max_tex_side_gen = generate_max_tex_side(max_tex_side); max_tex_layers = rand() % 4 ? 1 : 5; /* many partial copies, dimensions can be different */ tdst.width0 = (rand() % max_tex_side_gen) + 1; tdst.height0 = (rand() % max_tex_side_gen) + 1; tdst.array_size = (rand() % max_tex_layers) + 1; /* Have a 1/4 chance of getting power-of-two dimensions. */ if (rand() % 4 == 0) { tdst.width0 = util_next_power_of_two(tdst.width0); tdst.height0 = util_next_power_of_two(tdst.height0); } } /* check texture sizes */ if ((uint64_t)tsrc.width0 * tsrc.height0 * tsrc.array_size * bpp + (uint64_t)tdst.width0 * tdst.height0 * tdst.array_size * bpp > max_alloc_size) { /* too large, try again */ i--; continue; } /* VRAM + the tiling mode depends on dimensions (3/4 of cases), * or GTT + linear only (1/4 of cases) */ tsrc.usage = rand() % 4 ? PIPE_USAGE_DEFAULT : PIPE_USAGE_STAGING; tdst.usage = rand() % 4 ? PIPE_USAGE_DEFAULT : PIPE_USAGE_STAGING; /* Allocate textures (both the GPU and CPU copies). * The CPU will emulate what the GPU should be doing. */ src = screen->resource_create(screen, &tsrc); dst = screen->resource_create(screen, &tdst); assert(src); assert(dst); rdst = (struct r600_texture*)dst; rsrc = (struct r600_texture*)src; alloc_cpu_texture(&src_cpu, &tsrc, bpp); alloc_cpu_texture(&dst_cpu, &tdst, bpp); printf("%4u: dst = (%5u x %5u x %u, %s), " " src = (%5u x %5u x %u, %s), bpp = %2u, ", i, tdst.width0, tdst.height0, tdst.array_size, array_mode_to_string(rscreen, &rdst->surface), tsrc.width0, tsrc.height0, tsrc.array_size, array_mode_to_string(rscreen, &rsrc->surface), bpp); fflush(stdout); /* set src pixels */ set_random_pixels(ctx, src, &src_cpu); /* clear dst pixels */ rctx->clear_buffer(ctx, dst, 0, rdst->surface.surf_size, 0, true); memset(dst_cpu.ptr, 0, dst_cpu.layer_stride * tdst.array_size); /* preparation */ max_width = MIN2(tsrc.width0, tdst.width0); max_height = MIN2(tsrc.height0, tdst.height0); max_depth = MIN2(tsrc.array_size, tdst.array_size); num = do_partial_copies ? num_partial_copies : 1; for (j = 0; j < num; j++) { int width, height, depth; int srcx, srcy, srcz, dstx, dsty, dstz; struct pipe_box box; unsigned old_num_draw_calls = rctx->num_draw_calls; unsigned old_num_dma_calls = rctx->num_dma_calls; if (!do_partial_copies) { /* copy whole src to dst */ width = max_width; height = max_height; depth = max_depth; srcx = srcy = srcz = dstx = dsty = dstz = 0; } else { /* random sub-rectangle copies from src to dst */ depth = (rand() % max_depth) + 1; srcz = rand() % (tsrc.array_size - depth + 1); dstz = rand() % (tdst.array_size - depth + 1); /* special code path to hit the tiled partial copies */ if (!rsrc->surface.is_linear && !rdst->surface.is_linear && rand() & 1) { if (max_width < 8 || max_height < 8) continue; width = ((rand() % (max_width / 8)) + 1) * 8; height = ((rand() % (max_height / 8)) + 1) * 8; srcx = rand() % (tsrc.width0 - width + 1) & ~0x7; srcy = rand() % (tsrc.height0 - height + 1) & ~0x7; dstx = rand() % (tdst.width0 - width + 1) & ~0x7; dsty = rand() % (tdst.height0 - height + 1) & ~0x7; } else { /* just make sure that it doesn't divide by zero */ assert(max_width > 0 && max_height > 0); width = (rand() % max_width) + 1; height = (rand() % max_height) + 1; srcx = rand() % (tsrc.width0 - width + 1); srcy = rand() % (tsrc.height0 - height + 1); dstx = rand() % (tdst.width0 - width + 1); dsty = rand() % (tdst.height0 - height + 1); } /* special code path to hit out-of-bounds reads in L2T */ if (rsrc->surface.is_linear && !rdst->surface.is_linear && rand() % 4 == 0) { srcx = 0; srcy = 0; srcz = 0; } } /* GPU copy */ u_box_3d(srcx, srcy, srcz, width, height, depth, &box); rctx->dma_copy(ctx, dst, 0, dstx, dsty, dstz, src, 0, &box); /* See which engine was used. */ gfx_blits += rctx->num_draw_calls > old_num_draw_calls; dma_blits += rctx->num_dma_calls > old_num_dma_calls; /* CPU copy */ util_copy_box(dst_cpu.ptr, tdst.format, dst_cpu.stride, dst_cpu.layer_stride, dstx, dsty, dstz, width, height, depth, src_cpu.ptr, src_cpu.stride, src_cpu.layer_stride, srcx, srcy, srcz); } pass = compare_textures(ctx, dst, &dst_cpu, bpp); if (pass) num_pass++; else num_fail++; printf("BLITs: GFX = %2u, DMA = %2u, %s [%u/%u]\n", gfx_blits, dma_blits, pass ? "pass" : "fail", num_pass, num_pass+num_fail); /* cleanup */ pipe_resource_reference(&src, NULL); pipe_resource_reference(&dst, NULL); free(src_cpu.ptr); free(dst_cpu.ptr); } ctx->destroy(ctx); exit(0); }
void si_resource_copy_region(struct pipe_context *ctx, 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 si_context *sctx = (struct si_context *)ctx; struct pipe_surface *dst_view, dst_templ; struct pipe_sampler_view src_templ, *src_view; unsigned dst_width, dst_height, src_width0, src_height0; unsigned src_force_level = 0; struct pipe_box sbox, dstbox; /* Handle buffers first. */ if (dst->target == PIPE_BUFFER && src->target == PIPE_BUFFER) { si_copy_buffer(sctx, dst, src, dstx, src_box->x, src_box->width); return; } assert(u_max_sample(dst) == u_max_sample(src)); /* The driver doesn't decompress resources automatically while * u_blitter is rendering. */ si_decompress_subresource(ctx, src, PIPE_MASK_RGBAZS, src_level, src_box->z, src_box->z + src_box->depth - 1); dst_width = u_minify(dst->width0, dst_level); dst_height = u_minify(dst->height0, dst_level); src_width0 = src->width0; src_height0 = src->height0; util_blitter_default_dst_texture(&dst_templ, dst, dst_level, dstz); util_blitter_default_src_texture(&src_templ, src, src_level); if (util_format_is_compressed(src->format) || util_format_is_compressed(dst->format)) { unsigned blocksize = util_format_get_blocksize(src->format); if (blocksize == 8) src_templ.format = PIPE_FORMAT_R16G16B16A16_UINT; /* 64-bit block */ else src_templ.format = PIPE_FORMAT_R32G32B32A32_UINT; /* 128-bit block */ dst_templ.format = src_templ.format; dst_width = util_format_get_nblocksx(dst->format, dst_width); dst_height = util_format_get_nblocksy(dst->format, dst_height); src_width0 = util_format_get_nblocksx(src->format, src_width0); src_height0 = util_format_get_nblocksy(src->format, src_height0); dstx = util_format_get_nblocksx(dst->format, dstx); dsty = util_format_get_nblocksy(dst->format, dsty); sbox.x = util_format_get_nblocksx(src->format, src_box->x); sbox.y = util_format_get_nblocksy(src->format, src_box->y); sbox.z = src_box->z; sbox.width = util_format_get_nblocksx(src->format, src_box->width); sbox.height = util_format_get_nblocksy(src->format, src_box->height); sbox.depth = src_box->depth; src_box = &sbox; src_force_level = src_level; } else if (!util_blitter_is_copy_supported(sctx->blitter, dst, src) || /* also *8_SNORM has precision issues, use UNORM instead */ util_format_is_snorm8(src->format)) { if (util_format_is_subsampled_422(src->format)) { src_templ.format = PIPE_FORMAT_R8G8B8A8_UINT; dst_templ.format = PIPE_FORMAT_R8G8B8A8_UINT; dst_width = util_format_get_nblocksx(dst->format, dst_width); src_width0 = util_format_get_nblocksx(src->format, src_width0); dstx = util_format_get_nblocksx(dst->format, dstx); sbox = *src_box; sbox.x = util_format_get_nblocksx(src->format, src_box->x); sbox.width = util_format_get_nblocksx(src->format, src_box->width); src_box = &sbox; } else { unsigned blocksize = util_format_get_blocksize(src->format); switch (blocksize) { case 1: dst_templ.format = PIPE_FORMAT_R8_UNORM; src_templ.format = PIPE_FORMAT_R8_UNORM; break; case 2: dst_templ.format = PIPE_FORMAT_R8G8_UNORM; src_templ.format = PIPE_FORMAT_R8G8_UNORM; break; case 4: dst_templ.format = PIPE_FORMAT_R8G8B8A8_UNORM; src_templ.format = PIPE_FORMAT_R8G8B8A8_UNORM; break; case 8: dst_templ.format = PIPE_FORMAT_R16G16B16A16_UINT; src_templ.format = PIPE_FORMAT_R16G16B16A16_UINT; break; case 16: dst_templ.format = PIPE_FORMAT_R32G32B32A32_UINT; src_templ.format = PIPE_FORMAT_R32G32B32A32_UINT; break; default: fprintf(stderr, "Unhandled format %s with blocksize %u\n", util_format_short_name(src->format), blocksize); assert(0); } } } /* Initialize the surface. */ dst_view = r600_create_surface_custom(ctx, dst, &dst_templ, dst_width, dst_height); /* Initialize the sampler view. */ src_view = si_create_sampler_view_custom(ctx, src, &src_templ, src_width0, src_height0, src_force_level); u_box_3d(dstx, dsty, dstz, abs(src_box->width), abs(src_box->height), abs(src_box->depth), &dstbox); /* Copy. */ si_blitter_begin(ctx, SI_COPY); util_blitter_blit_generic(sctx->blitter, dst_view, &dstbox, src_view, src_box, src_width0, src_height0, PIPE_MASK_RGBAZS, PIPE_TEX_FILTER_NEAREST, NULL, FALSE); si_blitter_end(ctx); pipe_surface_reference(&dst_view, NULL); pipe_sampler_view_reference(&src_view, NULL); }
HRESULT NINE_WINAPI NineVolume9_LockBox( struct NineVolume9 *This, D3DLOCKED_BOX *pLockedVolume, const D3DBOX *pBox, DWORD Flags ) { struct pipe_resource *resource = This->resource; struct pipe_box box; unsigned usage; DBG("This=%p(%p) pLockedVolume=%p pBox=%p[%u..%u,%u..%u,%u..%u] Flags=%s\n", This, This->base.container, pLockedVolume, pBox, pBox ? pBox->Left : 0, pBox ? pBox->Right : 0, pBox ? pBox->Top : 0, pBox ? pBox->Bottom : 0, pBox ? pBox->Front : 0, pBox ? pBox->Back : 0, nine_D3DLOCK_to_str(Flags)); /* check if it's already locked */ user_assert(This->lock_count == 0, D3DERR_INVALIDCALL); /* set pBits to NULL after lock_count check */ user_assert(pLockedVolume, E_POINTER); pLockedVolume->pBits = NULL; user_assert(This->desc.Pool != D3DPOOL_DEFAULT || (This->desc.Usage & D3DUSAGE_DYNAMIC), D3DERR_INVALIDCALL); user_assert(!((Flags & D3DLOCK_DISCARD) && (Flags & D3DLOCK_READONLY)), D3DERR_INVALIDCALL); if (pBox && compressed_format (This->desc.Format)) { /* For volume all pools are checked */ const unsigned w = util_format_get_blockwidth(This->info.format); const unsigned h = util_format_get_blockheight(This->info.format); user_assert((pBox->Left == 0 && pBox->Right == This->desc.Width && pBox->Top == 0 && pBox->Bottom == This->desc.Height) || (!(pBox->Left % w) && !(pBox->Right % w) && !(pBox->Top % h) && !(pBox->Bottom % h)), D3DERR_INVALIDCALL); } if (Flags & D3DLOCK_DISCARD) { usage = PIPE_TRANSFER_WRITE | PIPE_TRANSFER_DISCARD_RANGE; } else { usage = (Flags & D3DLOCK_READONLY) ? PIPE_TRANSFER_READ : PIPE_TRANSFER_READ_WRITE; } if (Flags & D3DLOCK_DONOTWAIT) usage |= PIPE_TRANSFER_DONTBLOCK; if (pBox) { user_assert(pBox->Right > pBox->Left, D3DERR_INVALIDCALL); user_assert(pBox->Bottom > pBox->Top, D3DERR_INVALIDCALL); user_assert(pBox->Back > pBox->Front, D3DERR_INVALIDCALL); user_assert(pBox->Right <= This->desc.Width, D3DERR_INVALIDCALL); user_assert(pBox->Bottom <= This->desc.Height, D3DERR_INVALIDCALL); user_assert(pBox->Back <= This->desc.Depth, D3DERR_INVALIDCALL); d3dbox_to_pipe_box(&box, pBox); if (u_box_clip_2d(&box, &box, This->desc.Width, This->desc.Height) < 0) { DBG("Locked volume intersection empty.\n"); return D3DERR_INVALIDCALL; } } else { u_box_3d(0, 0, 0, This->desc.Width, This->desc.Height, This->desc.Depth, &box); } if (This->data_conversion) { /* For now we only have uncompressed formats here */ pLockedVolume->RowPitch = This->stride_conversion; pLockedVolume->SlicePitch = This->layer_stride_conversion; pLockedVolume->pBits = This->data_conversion + box.z * This->layer_stride_conversion + box.y * This->stride_conversion + util_format_get_stride(This->format_conversion, box.x); } else if (This->data) { pLockedVolume->RowPitch = This->stride; pLockedVolume->SlicePitch = This->layer_stride; pLockedVolume->pBits = NineVolume9_GetSystemMemPointer(This, box.x, box.y, box.z); } else { pLockedVolume->pBits = This->pipe->transfer_map(This->pipe, resource, This->level, usage, &box, &This->transfer); if (!This->transfer) { if (Flags & D3DLOCK_DONOTWAIT) return D3DERR_WASSTILLDRAWING; return D3DERR_DRIVERINTERNALERROR; } pLockedVolume->RowPitch = This->transfer->stride; pLockedVolume->SlicePitch = This->transfer->layer_stride; } if (!(Flags & (D3DLOCK_NO_DIRTY_UPDATE | D3DLOCK_READONLY))) { NineVolume9_MarkContainerDirty(This); NineVolume9_AddDirtyRegion(This, &box); } ++This->lock_count; return D3D_OK; }