radeonsi: don't change pipe_resource in resource_copy_region

Copied from r600g. pipe_resource can be shared by multiple threads, so we
shouldn't change it.

Reviewed-by: Michel Dänzer <michel.daenzer@amd.com>
This commit is contained in:
Marek Olšák 2015-07-16 13:17:14 +02:00
parent 50a957c5de
commit 46b2b3bda8
4 changed files with 110 additions and 160 deletions

View File

@ -214,7 +214,6 @@ struct r600_texture {
float depth_clear_value;
bool non_disp_tiling; /* R600-Cayman only */
unsigned mipmap_shift;
};
struct r600_surface {

View File

@ -455,89 +455,6 @@ struct texture_orig_info {
unsigned npix0_y;
};
static void si_compressed_to_blittable(struct pipe_resource *tex,
unsigned level,
struct texture_orig_info *orig)
{
struct r600_texture *rtex = (struct r600_texture*)tex;
unsigned pixsize = util_format_get_blocksize(rtex->resource.b.b.format);
int new_format;
int new_height, new_width;
orig->format = tex->format;
orig->width0 = tex->width0;
orig->height0 = tex->height0;
orig->npix0_x = rtex->surface.level[0].npix_x;
orig->npix0_y = rtex->surface.level[0].npix_y;
orig->npix_x = rtex->surface.level[level].npix_x;
orig->npix_y = rtex->surface.level[level].npix_y;
if (pixsize == 8)
new_format = PIPE_FORMAT_R16G16B16A16_UINT; /* 64-bit block */
else
new_format = PIPE_FORMAT_R32G32B32A32_UINT; /* 128-bit block */
new_width = util_format_get_nblocksx(tex->format, orig->width0);
new_height = util_format_get_nblocksy(tex->format, orig->height0);
tex->width0 = new_width;
tex->height0 = new_height;
tex->format = new_format;
rtex->surface.level[0].npix_x = util_format_get_nblocksx(orig->format, orig->npix0_x);
rtex->surface.level[0].npix_y = util_format_get_nblocksy(orig->format, orig->npix0_y);
rtex->surface.level[level].npix_x = util_format_get_nblocksx(orig->format, orig->npix_x);
rtex->surface.level[level].npix_y = util_format_get_nblocksy(orig->format, orig->npix_y);
/* By dividing the dimensions by 4, we effectively decrement
* last_level by 2, therefore the last 2 mipmap levels disappear and
* aren't blittable. Note that the last 3 mipmap levels (4x4, 2x2,
* 1x1) have equal slice sizes, which is an important assumption
* for this to work.
*
* In order to make the last 2 mipmap levels blittable, we have to
* add the slice size of the last mipmap level to the texture
* address, so that even though the hw thinks it reads last_level-2,
* it will actually read last_level-1, and if we add the slice size*2,
* it will read last_level. That's how this workaround works.
*/
if (level > rtex->resource.b.b.last_level-2)
rtex->mipmap_shift = level - (rtex->resource.b.b.last_level-2);
}
static void si_change_format(struct pipe_resource *tex,
unsigned level,
struct texture_orig_info *orig,
enum pipe_format format)
{
struct r600_texture *rtex = (struct r600_texture*)tex;
orig->format = tex->format;
orig->width0 = tex->width0;
orig->height0 = tex->height0;
orig->npix0_x = rtex->surface.level[0].npix_x;
orig->npix0_y = rtex->surface.level[0].npix_y;
orig->npix_x = rtex->surface.level[level].npix_x;
orig->npix_y = rtex->surface.level[level].npix_y;
tex->format = format;
}
static void si_reset_blittable_to_orig(struct pipe_resource *tex,
unsigned level,
struct texture_orig_info *orig)
{
struct r600_texture *rtex = (struct r600_texture*)tex;
tex->format = orig->format;
tex->width0 = orig->width0;
tex->height0 = orig->height0;
rtex->surface.level[0].npix_x = orig->npix0_x;
rtex->surface.level[0].npix_y = orig->npix0_y;
rtex->surface.level[level].npix_x = orig->npix_x;
rtex->surface.level[level].npix_y = orig->npix_y;
rtex->mipmap_shift = 0;
}
void si_resource_copy_region(struct pipe_context *ctx,
struct pipe_resource *dst,
unsigned dst_level,
@ -547,114 +464,114 @@ void si_resource_copy_region(struct pipe_context *ctx,
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];
unsigned dst_width, dst_height, src_width0, src_height0;
unsigned src_force_level = 0;
struct pipe_box sbox, dstbox;
boolean restore_orig[2];
/* Fallback for buffers. */
/* 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, false);
return;
}
memset(orig_info, 0, sizeof(orig_info));
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, src_level,
src_box->z, src_box->z + src_box->depth - 1);
restore_orig[0] = restore_orig[1] = FALSE;
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)) {
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);
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(orig_info[0].format, src_box->width);
sbox.height = util_format_get_nblocksy(orig_info[0].format, src_box->height);
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;
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);
src_force_level = src_level;
} 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);
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(orig_info[0].format, src_box->x);
sbox.width = util_format_get_nblocksx(orig_info[0].format, src_box->width);
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;
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);
dst_templ.format = PIPE_FORMAT_R8_UNORM;
src_templ.format = 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);
dst_templ.format = PIPE_FORMAT_R8G8_UNORM;
src_templ.format = 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);
dst_templ.format = PIPE_FORMAT_R8G8B8A8_UNORM;
src_templ.format = 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);
dst_templ.format = PIPE_FORMAT_R16G16B16A16_UINT;
src_templ.format = 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);
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);
}
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);
dst_width, dst_height);
/* Initialize the sampler view. */
util_blitter_default_src_texture(&src_templ, src, src_level);
src_view = ctx->create_sampler_view(ctx, src, &src_templ);
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);
@ -662,18 +579,12 @@ void si_resource_copy_region(struct pipe_context *ctx,
/* Copy. */
si_blitter_begin(ctx, SI_COPY);
util_blitter_blit_generic(sctx->blitter, dst_view, &dstbox,
src_view, src_box, src->width0, src->height0,
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]);
}
/* For MSAA integer resolving to work, we change the format to NORM using this function. */

View File

@ -2272,15 +2272,28 @@ static void si_set_min_samples(struct pipe_context *ctx, unsigned min_samples)
* Samplers
*/
static struct pipe_sampler_view *si_create_sampler_view(struct pipe_context *ctx,
struct pipe_resource *texture,
const struct pipe_sampler_view *state)
/**
* Create a sampler view.
*
* @param ctx context
* @param texture texture
* @param state sampler view template
* @param width0 width0 override (for compressed textures as int)
* @param height0 height0 override (for compressed textures as int)
* @param force_level set the base address to the level (for compressed textures)
*/
struct pipe_sampler_view *
si_create_sampler_view_custom(struct pipe_context *ctx,
struct pipe_resource *texture,
const struct pipe_sampler_view *state,
unsigned width0, unsigned height0,
unsigned force_level)
{
struct si_context *sctx = (struct si_context*)ctx;
struct si_sampler_view *view = CALLOC_STRUCT(si_sampler_view);
struct r600_texture *tmp = (struct r600_texture*)texture;
const struct util_format_description *desc;
unsigned format, num_format;
unsigned format, num_format, base_level, first_level, last_level;
uint32_t pitch = 0;
unsigned char state_swizzle[4], swizzle[4];
unsigned height, depth, width;
@ -2453,13 +2466,25 @@ static struct pipe_sampler_view *si_create_sampler_view(struct pipe_context *ctx
format = 0;
}
/* not supported any more */
//endian = si_colorformat_endian_swap(format);
base_level = 0;
first_level = state->u.tex.first_level;
last_level = state->u.tex.last_level;
width = width0;
height = height0;
depth = texture->depth0;
width = surflevel[0].npix_x;
height = surflevel[0].npix_y;
depth = surflevel[0].npix_z;
pitch = surflevel[0].nblk_x * util_format_get_blockwidth(pipe_format);
if (force_level) {
assert(force_level == first_level &&
force_level == last_level);
base_level = force_level;
first_level = 0;
last_level = 0;
width = u_minify(width, force_level);
height = u_minify(height, force_level);
depth = u_minify(depth, force_level);
}
pitch = surflevel[base_level].nblk_x * util_format_get_blockwidth(pipe_format);
if (texture->target == PIPE_TEXTURE_1D_ARRAY) {
height = 1;
@ -2469,8 +2494,7 @@ static struct pipe_sampler_view *si_create_sampler_view(struct pipe_context *ctx
} else if (texture->target == PIPE_TEXTURE_CUBE_ARRAY)
depth = texture->array_size / 6;
va = tmp->resource.gpu_address + surflevel[0].offset;
va += tmp->mipmap_shift * surflevel[texture->last_level].slice_size * tmp->surface.array_size;
va = tmp->resource.gpu_address + surflevel[base_level].offset;
view->state[0] = va >> 8;
view->state[1] = (S_008F14_BASE_ADDRESS_HI(va >> 40) |
@ -2483,10 +2507,10 @@ static struct pipe_sampler_view *si_create_sampler_view(struct pipe_context *ctx
S_008F1C_DST_SEL_Z(si_map_swizzle(swizzle[2])) |
S_008F1C_DST_SEL_W(si_map_swizzle(swizzle[3])) |
S_008F1C_BASE_LEVEL(texture->nr_samples > 1 ?
0 : state->u.tex.first_level - tmp->mipmap_shift) |
0 : first_level) |
S_008F1C_LAST_LEVEL(texture->nr_samples > 1 ?
util_logbase2(texture->nr_samples) :
state->u.tex.last_level - tmp->mipmap_shift) |
last_level) |
S_008F1C_TILING_INDEX(si_tile_mode_index(tmp, 0, false)) |
S_008F1C_POW2_PAD(texture->last_level > 0) |
S_008F1C_TYPE(si_tex_dim(texture->target, texture->nr_samples)));
@ -2539,6 +2563,16 @@ static struct pipe_sampler_view *si_create_sampler_view(struct pipe_context *ctx
return &view->base;
}
static struct pipe_sampler_view *
si_create_sampler_view(struct pipe_context *ctx,
struct pipe_resource *texture,
const struct pipe_sampler_view *state)
{
return si_create_sampler_view_custom(ctx, texture, state,
texture ? texture->width0 : 0,
texture ? texture->height0 : 0, 0);
}
static void si_sampler_view_destroy(struct pipe_context *ctx,
struct pipe_sampler_view *state)
{

View File

@ -264,6 +264,12 @@ unsigned cik_tile_split(unsigned tile_split);
unsigned si_array_mode(unsigned mode);
uint32_t si_num_banks(struct si_screen *sscreen, struct r600_texture *tex);
unsigned si_tile_mode_index(struct r600_texture *rtex, unsigned level, bool stencil);
struct pipe_sampler_view *
si_create_sampler_view_custom(struct pipe_context *ctx,
struct pipe_resource *texture,
const struct pipe_sampler_view *state,
unsigned width0, unsigned height0,
unsigned force_level);
/* si_state_shader.c */
void si_update_shaders(struct si_context *sctx);