summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVadim Girlin <vadimgirlin@gmail.com>2012-07-11 02:19:51 +0400
committerVadim Girlin <vadimgirlin@gmail.com>2012-07-11 02:39:59 +0400
commit37708479608af877986b76302a9c92611d1e23d0 (patch)
treef66db9d3760b8402df29044b59e70f7e59c7b451
parent860d5bdf984730f69cd19b4f7145f3c84b57d33d (diff)
r600g: improve flushed depth texture handling v2
Use r600_resource_texture::flished_depth_texture for GPU access, and allocate it in the VRAM. For transfers we'll allocate texture in the GTT and store it in the r600_transfer::staging. Improves performance when flushed depth texture is frequently used by the GPU, e.g. in Lightsmark (~30%) Signed-off-by: Vadim Girlin <vadimgirlin@gmail.com>
-rw-r--r--src/gallium/drivers/r600/evergreen_state.c5
-rw-r--r--src/gallium/drivers/r600/r600_blit.c21
-rw-r--r--src/gallium/drivers/r600/r600_pipe.h4
-rw-r--r--src/gallium/drivers/r600/r600_resource.h6
-rw-r--r--src/gallium/drivers/r600/r600_state.c2
-rw-r--r--src/gallium/drivers/r600/r600_texture.c106
6 files changed, 83 insertions, 61 deletions
diff --git a/src/gallium/drivers/r600/evergreen_state.c b/src/gallium/drivers/r600/evergreen_state.c
index bbdc5868a80..60825bc7244 100644
--- a/src/gallium/drivers/r600/evergreen_state.c
+++ b/src/gallium/drivers/r600/evergreen_state.c
@@ -990,7 +990,7 @@ static struct pipe_sampler_view *evergreen_create_sampler_view(struct pipe_conte
990 } 990 }
991 991
992 if (tmp->is_depth && !tmp->is_flushing_texture) { 992 if (tmp->is_depth && !tmp->is_flushing_texture) {
993 r600_init_flushed_depth_texture(ctx, texture); 993 r600_init_flushed_depth_texture(ctx, texture, NULL);
994 tmp = tmp->flushed_depth_texture; 994 tmp = tmp->flushed_depth_texture;
995 if (!tmp) { 995 if (!tmp) {
996 FREE(view); 996 FREE(view);
@@ -1318,7 +1318,8 @@ void evergreen_cb(struct r600_context *rctx, struct r600_pipe_state *rstate,
1318 rctx->have_depth_fb = TRUE; 1318 rctx->have_depth_fb = TRUE;
1319 1319
1320 if (rtex->is_depth && !rtex->is_flushing_texture) { 1320 if (rtex->is_depth && !rtex->is_flushing_texture) {
1321 r600_init_flushed_depth_texture(&rctx->context, state->cbufs[cb]->texture); 1321 r600_init_flushed_depth_texture(&rctx->context,
1322 state->cbufs[cb]->texture, NULL);
1322 rtex = rtex->flushed_depth_texture; 1323 rtex = rtex->flushed_depth_texture;
1323 assert(rtex); 1324 assert(rtex);
1324 } 1325 }
diff --git a/src/gallium/drivers/r600/r600_blit.c b/src/gallium/drivers/r600/r600_blit.c
index 4c72f16b701..d85324b6fbb 100644
--- a/src/gallium/drivers/r600/r600_blit.c
+++ b/src/gallium/drivers/r600/r600_blit.c
@@ -114,13 +114,17 @@ static unsigned u_num_layers(struct pipe_resource *r, unsigned level)
114 } 114 }
115} 115}
116 116
117void r600_blit_uncompress_depth(struct pipe_context *ctx, struct r600_resource_texture *texture) 117void r600_blit_uncompress_depth(struct pipe_context *ctx,
118 struct r600_resource_texture *texture,
119 struct r600_resource_texture *staging)
118{ 120{
119 struct r600_context *rctx = (struct r600_context *)ctx; 121 struct r600_context *rctx = (struct r600_context *)ctx;
120 unsigned layer, level; 122 unsigned layer, level;
121 float depth = 1.0f; 123 float depth = 1.0f;
124 struct r600_resource_texture *flushed_depth_texture = staging ?
125 staging : texture->flushed_depth_texture;
122 126
123 if (!texture->dirty_db) 127 if (!staging && !texture->dirty_db)
124 return; 128 return;
125 129
126 if (rctx->family == CHIP_RV610 || rctx->family == CHIP_RV630 || 130 if (rctx->family == CHIP_RV610 || rctx->family == CHIP_RV630 ||
@@ -141,10 +145,10 @@ void r600_blit_uncompress_depth(struct pipe_context *ctx, struct r600_resource_t
141 145
142 zsurf = ctx->create_surface(ctx, &texture->resource.b.b, &surf_tmpl); 146 zsurf = ctx->create_surface(ctx, &texture->resource.b.b, &surf_tmpl);
143 147
144 surf_tmpl.format = texture->flushed_depth_texture->real_format; 148 surf_tmpl.format = flushed_depth_texture->real_format;
145 surf_tmpl.usage = PIPE_BIND_RENDER_TARGET; 149 surf_tmpl.usage = PIPE_BIND_RENDER_TARGET;
146 cbsurf = ctx->create_surface(ctx, 150 cbsurf = ctx->create_surface(ctx,
147 (struct pipe_resource*)texture->flushed_depth_texture, &surf_tmpl); 151 (struct pipe_resource*)flushed_depth_texture, &surf_tmpl);
148 152
149 r600_blitter_begin(ctx, R600_DECOMPRESS); 153 r600_blitter_begin(ctx, R600_DECOMPRESS);
150 util_blitter_custom_depth_stencil(rctx->blitter, zsurf, cbsurf, rctx->custom_dsa_flush, depth); 154 util_blitter_custom_depth_stencil(rctx->blitter, zsurf, cbsurf, rctx->custom_dsa_flush, depth);
@@ -155,7 +159,8 @@ void r600_blit_uncompress_depth(struct pipe_context *ctx, struct r600_resource_t
155 } 159 }
156 } 160 }
157 161
158 texture->dirty_db = FALSE; 162 if (!staging)
163 texture->dirty_db = FALSE;
159} 164}
160 165
161void r600_flush_depth_textures(struct r600_context *rctx) 166void r600_flush_depth_textures(struct r600_context *rctx)
@@ -178,7 +183,7 @@ void r600_flush_depth_textures(struct r600_context *rctx)
178 if (tex->is_flushing_texture) 183 if (tex->is_flushing_texture)
179 continue; 184 continue;
180 185
181 r600_blit_uncompress_depth(&rctx->context, tex); 186 r600_blit_uncompress_depth(&rctx->context, tex, NULL);
182 } 187 }
183 188
184 /* also check CB here */ 189 /* also check CB here */
@@ -192,7 +197,7 @@ void r600_flush_depth_textures(struct r600_context *rctx)
192 if (tex->is_flushing_texture) 197 if (tex->is_flushing_texture)
193 continue; 198 continue;
194 199
195 r600_blit_uncompress_depth(&rctx->context, tex); 200 r600_blit_uncompress_depth(&rctx->context, tex, NULL);
196 } 201 }
197} 202}
198 203
@@ -324,7 +329,7 @@ static void r600_resource_copy_region(struct pipe_context *ctx,
324 } 329 }
325 330
326 if (rsrc->is_depth && !rsrc->is_flushing_texture) 331 if (rsrc->is_depth && !rsrc->is_flushing_texture)
327 r600_texture_depth_flush(ctx, src); 332 r600_texture_depth_flush(ctx, src, NULL);
328 333
329 restore_orig[0] = restore_orig[1] = FALSE; 334 restore_orig[0] = restore_orig[1] = FALSE;
330 335
diff --git a/src/gallium/drivers/r600/r600_pipe.h b/src/gallium/drivers/r600/r600_pipe.h
index de43555ddbf..0785ade4162 100644
--- a/src/gallium/drivers/r600/r600_pipe.h
+++ b/src/gallium/drivers/r600/r600_pipe.h
@@ -433,7 +433,9 @@ void evergreen_update_dual_export_state(struct r600_context * rctx);
433 433
434/* r600_blit.c */ 434/* r600_blit.c */
435void r600_init_blit_functions(struct r600_context *rctx); 435void r600_init_blit_functions(struct r600_context *rctx);
436void r600_blit_uncompress_depth(struct pipe_context *ctx, struct r600_resource_texture *texture); 436void r600_blit_uncompress_depth(struct pipe_context *ctx,
437 struct r600_resource_texture *texture,
438 struct r600_resource_texture *staging);
437void r600_flush_depth_textures(struct r600_context *rctx); 439void r600_flush_depth_textures(struct r600_context *rctx);
438 440
439/* r600_buffer.c */ 441/* r600_buffer.c */
diff --git a/src/gallium/drivers/r600/r600_resource.h b/src/gallium/drivers/r600/r600_resource.h
index d1f3a4766ca..7327ba6c2d7 100644
--- a/src/gallium/drivers/r600/r600_resource.h
+++ b/src/gallium/drivers/r600/r600_resource.h
@@ -89,9 +89,11 @@ static INLINE struct r600_resource *r600_resource(struct pipe_resource *r)
89} 89}
90 90
91void r600_init_flushed_depth_texture(struct pipe_context *ctx, 91void r600_init_flushed_depth_texture(struct pipe_context *ctx,
92 struct pipe_resource *texture); 92 struct pipe_resource *texture,
93 struct r600_resource_texture **staging);
93void r600_texture_depth_flush(struct pipe_context *ctx, 94void r600_texture_depth_flush(struct pipe_context *ctx,
94 struct pipe_resource *texture); 95 struct pipe_resource *texture,
96 struct r600_resource_texture **staging);
95 97
96/* r600_texture.c texture transfer functions. */ 98/* r600_texture.c texture transfer functions. */
97struct pipe_transfer* r600_texture_get_transfer(struct pipe_context *ctx, 99struct pipe_transfer* r600_texture_get_transfer(struct pipe_context *ctx,
diff --git a/src/gallium/drivers/r600/r600_state.c b/src/gallium/drivers/r600/r600_state.c
index d51c64bca5e..0ba7fade043 100644
--- a/src/gallium/drivers/r600/r600_state.c
+++ b/src/gallium/drivers/r600/r600_state.c
@@ -1002,7 +1002,7 @@ static struct pipe_sampler_view *r600_create_sampler_view(struct pipe_context *c
1002 } 1002 }
1003 1003
1004 if (tmp->is_depth && !tmp->is_flushing_texture) { 1004 if (tmp->is_depth && !tmp->is_flushing_texture) {
1005 r600_init_flushed_depth_texture(ctx, texture); 1005 r600_init_flushed_depth_texture(ctx, texture, NULL);
1006 tmp = tmp->flushed_depth_texture; 1006 tmp = tmp->flushed_depth_texture;
1007 if (!tmp) { 1007 if (!tmp) {
1008 FREE(view); 1008 FREE(view);
diff --git a/src/gallium/drivers/r600/r600_texture.c b/src/gallium/drivers/r600/r600_texture.c
index d8c5df3159c..da6634643a3 100644
--- a/src/gallium/drivers/r600/r600_texture.c
+++ b/src/gallium/drivers/r600/r600_texture.c
@@ -295,7 +295,8 @@ static int r600_init_surface(struct radeon_surface *surface,
295 if (ptex->bind & PIPE_BIND_SCANOUT) { 295 if (ptex->bind & PIPE_BIND_SCANOUT) {
296 surface->flags |= RADEON_SURF_SCANOUT; 296 surface->flags |= RADEON_SURF_SCANOUT;
297 } 297 }
298 if (util_format_is_depth_and_stencil(ptex->format) && !is_transfer) { 298 if ((ptex->bind & PIPE_BIND_DEPTH_STENCIL) &&
299 util_format_is_depth_and_stencil(ptex->format) && !is_transfer) {
299 surface->flags |= RADEON_SURF_ZBUFFER; 300 surface->flags |= RADEON_SURF_ZBUFFER;
300 surface->flags |= RADEON_SURF_SBUFFER; 301 surface->flags |= RADEON_SURF_SBUFFER;
301 } 302 }
@@ -514,7 +515,7 @@ r600_texture_create_object(struct pipe_screen *screen,
514 rtex->real_format = base->format; 515 rtex->real_format = base->format;
515 516
516 /* We must split depth and stencil into two separate buffers on Evergreen. */ 517 /* We must split depth and stencil into two separate buffers on Evergreen. */
517 if (!(base->flags & R600_RESOURCE_FLAG_TRANSFER) && 518 if ((base->bind & PIPE_BIND_DEPTH_STENCIL) &&
518 ((struct r600_screen*)screen)->chip_class >= EVERGREEN && 519 ((struct r600_screen*)screen)->chip_class >= EVERGREEN &&
519 util_format_is_depth_and_stencil(base->format) && 520 util_format_is_depth_and_stencil(base->format) &&
520 !rscreen->use_surface_alloc) { 521 !rscreen->use_surface_alloc) {
@@ -558,7 +559,8 @@ r600_texture_create_object(struct pipe_screen *screen,
558 } 559 }
559 560
560 /* only mark depth textures the HW can hit as depth textures */ 561 /* only mark depth textures the HW can hit as depth textures */
561 if (util_format_is_depth_or_stencil(rtex->real_format) && permit_hardware_blit(screen, base)) 562 if (util_format_is_depth_or_stencil(rtex->real_format) &&
563 permit_hardware_blit(screen, base))
562 rtex->is_depth = true; 564 rtex->is_depth = true;
563 565
564 r600_setup_miptree(screen, rtex, array_mode); 566 r600_setup_miptree(screen, rtex, array_mode);
@@ -726,12 +728,15 @@ struct pipe_resource *r600_texture_from_handle(struct pipe_screen *screen,
726} 728}
727 729
728void r600_init_flushed_depth_texture(struct pipe_context *ctx, 730void r600_init_flushed_depth_texture(struct pipe_context *ctx,
729 struct pipe_resource *texture) 731 struct pipe_resource *texture,
732 struct r600_resource_texture **staging)
730{ 733{
731 struct r600_resource_texture *rtex = (struct r600_resource_texture*)texture; 734 struct r600_resource_texture *rtex = (struct r600_resource_texture*)texture;
732 struct pipe_resource resource; 735 struct pipe_resource resource;
736 struct r600_resource_texture **flushed_depth_texture = staging ?
737 staging : &rtex->flushed_depth_texture;
733 738
734 if (rtex->flushed_depth_texture) 739 if (!staging && rtex->flushed_depth_texture)
735 return; /* it's ready */ 740 return; /* it's ready */
736 741
737 resource.target = texture->target; 742 resource.target = texture->target;
@@ -742,32 +747,44 @@ void r600_init_flushed_depth_texture(struct pipe_context *ctx,
742 resource.array_size = texture->array_size; 747 resource.array_size = texture->array_size;
743 resource.last_level = texture->last_level; 748 resource.last_level = texture->last_level;
744 resource.nr_samples = texture->nr_samples; 749 resource.nr_samples = texture->nr_samples;
745 resource.usage = PIPE_USAGE_DYNAMIC; 750 resource.usage = staging ? PIPE_USAGE_DYNAMIC : PIPE_USAGE_DEFAULT;
746 resource.bind = texture->bind | PIPE_BIND_DEPTH_STENCIL; 751 resource.bind = texture->bind & ~PIPE_BIND_DEPTH_STENCIL;
747 resource.flags = R600_RESOURCE_FLAG_TRANSFER | texture->flags; 752 resource.flags = texture->flags;
753
754 if (staging)
755 resource.flags |= R600_RESOURCE_FLAG_TRANSFER;
756 else
757 rtex->dirty_db = TRUE;
748 758
749 rtex->flushed_depth_texture = (struct r600_resource_texture *)ctx->screen->resource_create(ctx->screen, &resource); 759 *flushed_depth_texture = (struct r600_resource_texture *)ctx->screen->resource_create(ctx->screen, &resource);
750 if (rtex->flushed_depth_texture == NULL) { 760 if (*flushed_depth_texture == NULL) {
751 R600_ERR("failed to create temporary texture to hold untiled copy\n"); 761 R600_ERR("failed to create temporary texture to hold flushed depth\n");
752 return; 762 return;
753 } 763 }
754 764
755 ((struct r600_resource_texture *)rtex->flushed_depth_texture)->is_flushing_texture = TRUE; 765 (*flushed_depth_texture)->is_flushing_texture = TRUE;
766
756} 767}
757 768
758void r600_texture_depth_flush(struct pipe_context *ctx, 769void r600_texture_depth_flush(struct pipe_context *ctx,
759 struct pipe_resource *texture) 770 struct pipe_resource *texture,
771 struct r600_resource_texture **staging)
760{ 772{
761 struct r600_resource_texture *rtex = (struct r600_resource_texture*)texture; 773 struct r600_resource_texture *rtex = (struct r600_resource_texture*)texture;
762 774
763 r600_init_flushed_depth_texture(ctx, texture); 775 r600_init_flushed_depth_texture(ctx, texture, staging);
764 776
765 if (!rtex->flushed_depth_texture) 777 if (staging) {
766 return; /* error */ 778 if (!*staging)
779 return; /* error */
767 780
768 /* XXX: only do this if the depth texture has actually changed: 781 r600_blit_uncompress_depth(ctx, rtex, *staging);
769 */ 782 } else {
770 r600_blit_uncompress_depth(ctx, rtex); 783 if (!rtex->flushed_depth_texture)
784 return; /* error */
785
786 r600_blit_uncompress_depth(ctx, rtex, NULL);
787 }
771} 788}
772 789
773/* Needs adjustment for pixelformat: 790/* Needs adjustment for pixelformat:
@@ -831,15 +848,18 @@ struct pipe_transfer* r600_texture_get_transfer(struct pipe_context *ctx,
831 */ 848 */
832 /* XXX: when discard is true, no need to read back from depth texture 849 /* XXX: when discard is true, no need to read back from depth texture
833 */ 850 */
834 r600_texture_depth_flush(ctx, texture); 851 struct r600_resource_texture *staging_depth;
835 if (!rtex->flushed_depth_texture) { 852
853 r600_texture_depth_flush(ctx, texture, &staging_depth);
854 if (!staging_depth) {
836 R600_ERR("failed to create temporary texture to hold untiled copy\n"); 855 R600_ERR("failed to create temporary texture to hold untiled copy\n");
837 pipe_resource_reference(&trans->transfer.resource, NULL); 856 pipe_resource_reference(&trans->transfer.resource, NULL);
838 FREE(trans); 857 FREE(trans);
839 return NULL; 858 return NULL;
840 } 859 }
841 trans->transfer.stride = rtex->flushed_depth_texture->pitch_in_bytes[level]; 860 trans->transfer.stride = staging_depth->pitch_in_bytes[level];
842 trans->offset = r600_texture_get_offset(rtex->flushed_depth_texture, level, box->z); 861 trans->offset = r600_texture_get_offset(staging_depth, level, box->z);
862 trans->staging = (struct r600_resource*)staging_depth;
843 return &trans->transfer; 863 return &trans->transfer;
844 } else if (use_staging_texture) { 864 } else if (use_staging_texture) {
845 resource.target = PIPE_TEXTURE_2D; 865 resource.target = PIPE_TEXTURE_2D;
@@ -894,25 +914,25 @@ void r600_texture_transfer_destroy(struct pipe_context *ctx,
894 struct pipe_resource *texture = transfer->resource; 914 struct pipe_resource *texture = transfer->resource;
895 struct r600_resource_texture *rtex = (struct r600_resource_texture*)texture; 915 struct r600_resource_texture *rtex = (struct r600_resource_texture*)texture;
896 916
897 if (rtransfer->staging) { 917 if (rtex->is_depth) {
898 if (transfer->usage & PIPE_TRANSFER_WRITE) { 918 if ((transfer->usage & PIPE_TRANSFER_WRITE) && rtransfer->staging) {
899 r600_copy_from_staging_texture(ctx, rtransfer);
900 }
901 pipe_resource_reference((struct pipe_resource**)&rtransfer->staging, NULL);
902 }
903
904 if (rtex->is_depth && !rtex->is_flushing_texture) {
905 if ((transfer->usage & PIPE_TRANSFER_WRITE) && rtex->flushed_depth_texture) {
906 struct pipe_box sbox; 919 struct pipe_box sbox;
907 920
908 u_box_origin_2d(texture->width0, texture->height0, &sbox); 921 u_box_origin_2d(texture->width0, texture->height0, &sbox);
909 922
910 ctx->resource_copy_region(ctx, texture, 0, 0, 0, 0, 923 ctx->resource_copy_region(ctx, texture, 0, 0, 0, 0,
911 &rtex->flushed_depth_texture->resource.b.b, 0, 924 &rtransfer->staging->b.b, 0,
912 &sbox); 925 &sbox);
913 } 926 }
927 } else if (rtransfer->staging) {
928 if (transfer->usage & PIPE_TRANSFER_WRITE) {
929 r600_copy_from_staging_texture(ctx, rtransfer);
930 }
914 } 931 }
915 932
933 if (rtransfer->staging)
934 pipe_resource_reference((struct pipe_resource**)&rtransfer->staging, NULL);
935
916 pipe_resource_reference(&transfer->resource, NULL); 936 pipe_resource_reference(&transfer->resource, NULL);
917 FREE(transfer); 937 FREE(transfer);
918} 938}
@@ -923,6 +943,8 @@ void* r600_texture_transfer_map(struct pipe_context *ctx,
923 struct r600_context *rctx = (struct r600_context *)ctx; 943 struct r600_context *rctx = (struct r600_context *)ctx;
924 struct r600_transfer *rtransfer = (struct r600_transfer*)transfer; 944 struct r600_transfer *rtransfer = (struct r600_transfer*)transfer;
925 struct radeon_winsys_cs_handle *buf; 945 struct radeon_winsys_cs_handle *buf;
946 struct r600_resource_texture *rtex =
947 (struct r600_resource_texture*)transfer->resource;
926 enum pipe_format format = transfer->resource->format; 948 enum pipe_format format = transfer->resource->format;
927 unsigned offset = 0; 949 unsigned offset = 0;
928 char *map; 950 char *map;
@@ -934,17 +956,13 @@ void* r600_texture_transfer_map(struct pipe_context *ctx,
934 if (rtransfer->staging) { 956 if (rtransfer->staging) {
935 buf = ((struct r600_resource *)rtransfer->staging)->cs_buf; 957 buf = ((struct r600_resource *)rtransfer->staging)->cs_buf;
936 } else { 958 } else {
937 struct r600_resource_texture *rtex = (struct r600_resource_texture*)transfer->resource; 959 buf = ((struct r600_resource *)transfer->resource)->cs_buf;
938 960 }
939 if (rtex->flushed_depth_texture)
940 buf = ((struct r600_resource *)rtex->flushed_depth_texture)->cs_buf;
941 else
942 buf = ((struct r600_resource *)transfer->resource)->cs_buf;
943 961
962 if (rtex->is_depth || !rtransfer->staging)
944 offset = rtransfer->offset + 963 offset = rtransfer->offset +
945 transfer->box.y / util_format_get_blockheight(format) * transfer->stride + 964 transfer->box.y / util_format_get_blockheight(format) * transfer->stride +
946 transfer->box.x / util_format_get_blockwidth(format) * util_format_get_blocksize(format); 965 transfer->box.x / util_format_get_blockwidth(format) * util_format_get_blocksize(format);
947 }
948 966
949 if (!(map = rctx->ws->buffer_map(buf, rctx->cs, transfer->usage))) { 967 if (!(map = rctx->ws->buffer_map(buf, rctx->cs, transfer->usage))) {
950 return NULL; 968 return NULL;
@@ -967,13 +985,7 @@ void r600_texture_transfer_unmap(struct pipe_context *ctx,
967 if (rtransfer->staging) { 985 if (rtransfer->staging) {
968 buf = ((struct r600_resource *)rtransfer->staging)->cs_buf; 986 buf = ((struct r600_resource *)rtransfer->staging)->cs_buf;
969 } else { 987 } else {
970 struct r600_resource_texture *rtex = (struct r600_resource_texture*)transfer->resource; 988 buf = ((struct r600_resource *)transfer->resource)->cs_buf;
971
972 if (rtex->flushed_depth_texture) {
973 buf = ((struct r600_resource *)rtex->flushed_depth_texture)->cs_buf;
974 } else {
975 buf = ((struct r600_resource *)transfer->resource)->cs_buf;
976 }
977 } 989 }
978 rctx->ws->buffer_unmap(buf); 990 rctx->ws->buffer_unmap(buf);
979} 991}