st/nine: Use nine_context_box_upload for surfaces
authorAxel Davy <axel.davy@ens.fr>
Sat, 3 Dec 2016 23:19:45 +0000 (00:19 +0100)
committerAxel Davy <axel.davy@ens.fr>
Tue, 20 Dec 2016 22:47:08 +0000 (23:47 +0100)
Use nine_context_box_upload for uploads:
. systemmem surface to default surface
. managed surface internal content to its resource.

Check the uploads are executed before any action
that can alter the data, that is LockRect,
NineSurface9_CopyDefaultToMem and surface destruction.

Signed-off-by: Axel Davy <axel.davy@ens.fr>
src/gallium/state_trackers/nine/surface9.c
src/gallium/state_trackers/nine/surface9.h

index 6373f6908d5f2fa1ac75dfe0ad8b7cb59274fb83..f7e479a26c4e1dc81762a100267f46ff82a225ae 100644 (file)
@@ -205,6 +205,9 @@ NineSurface9_dtor( struct NineSurface9 *This )
     if (This->transfer)
         NineSurface9_UnlockRect(This);
 
+    if (p_atomic_read(&This->pending_uploads_counter))
+        nine_csmt_process(This->base.base.device);
+
     pipe_surface_reference(&This->surface[0], NULL);
     pipe_surface_reference(&This->surface[1], NULL);
 
@@ -452,6 +455,9 @@ NineSurface9_LockRect( struct NineSurface9 *This,
 
     user_warn(This->desc.Format == D3DFMT_NULL);
 
+    if (p_atomic_read(&This->pending_uploads_counter))
+        nine_csmt_process(This->base.base.device);
+
     if (This->data_conversion) {
         /* For now we only have uncompressed formats here */
         pLockedRect->Pitch = This->stride_conversion;
@@ -588,11 +594,8 @@ NineSurface9_CopyMemToDefault( struct NineSurface9 *This,
                                const POINT *pDestPoint,
                                const RECT *pSourceRect )
 {
-    struct pipe_context *pipe;
-    struct pipe_transfer *transfer = NULL;
     struct pipe_resource *r_dst = This->base.resource;
-    struct pipe_box dst_box;
-    uint8_t *map = NULL;
+    struct pipe_box dst_box, src_box;
     int src_x, src_y, dst_x, dst_y, copy_width, copy_height;
 
     assert(This->base.pool == D3DPOOL_DEFAULT &&
@@ -620,27 +623,18 @@ NineSurface9_CopyMemToDefault( struct NineSurface9 *This,
 
     u_box_2d_zslice(dst_x, dst_y, This->layer,
                     copy_width, copy_height, &dst_box);
-
-    pipe = NineDevice9_GetPipe(This->base.base.device);
-    map = pipe->transfer_map(pipe,
-                             r_dst,
-                             This->level,
-                             PIPE_TRANSFER_WRITE | PIPE_TRANSFER_DISCARD_RANGE,
-                             &dst_box, &transfer);
-    if (!map)
-        return;
-
-    /* Note: if formats are the sames, it will revert
-     * to normal memcpy */
-    (void) util_format_translate(r_dst->format,
-                                 map, transfer->stride,
-                                 0, 0,
-                                 From->base.info.format,
-                                 From->data, From->stride,
-                                 src_x, src_y,
-                                 copy_width, copy_height);
-
-    pipe_transfer_unmap(pipe, transfer);
+    u_box_2d_zslice(src_x, src_y, 0,
+                    copy_width, copy_height, &src_box);
+
+    nine_context_box_upload(This->base.base.device,
+                            &From->pending_uploads_counter,
+                            r_dst,
+                            This->level,
+                            &dst_box,
+                            From->base.info.format,
+                            From->data, From->stride,
+                            0, /* depth = 1 */
+                            &src_box);
 
     if (This->data_conversion)
         (void) util_format_translate(This->format_conversion,
@@ -675,6 +669,9 @@ NineSurface9_CopyDefaultToMem( struct NineSurface9 *This,
     u_box_origin_2d(This->desc.Width, This->desc.Height, &src_box);
     src_box.z = From->layer;
 
+    if (p_atomic_read(&This->pending_uploads_counter))
+        nine_csmt_process(This->base.base.device);
+
     pipe = NineDevice9_GetPipe(This->base.base.device);
     p_src = pipe->transfer_map(pipe, r_src, From->level,
                                PIPE_TRANSFER_READ,
@@ -700,9 +697,7 @@ HRESULT
 NineSurface9_UploadSelf( struct NineSurface9 *This,
                          const struct pipe_box *damaged )
 {
-    struct pipe_context *pipe;
     struct pipe_resource *res = This->base.resource;
-    uint8_t *ptr;
     struct pipe_box box;
 
     DBG("This=%p damaged=%p\n", This, damaged);
@@ -722,11 +717,15 @@ NineSurface9_UploadSelf( struct NineSurface9 *This,
         box.depth = 1;
     }
 
-    ptr = NineSurface9_GetSystemMemPointer(This, box.x, box.y);
-
-    pipe = NineDevice9_GetPipe(This->base.base.device);
-    pipe->texture_subdata(pipe, res, This->level, 0,
-                          &box, ptr, This->stride, 0);
+    nine_context_box_upload(This->base.base.device,
+                            &This->pending_uploads_counter,
+                            res,
+                            This->level,
+                            &box,
+                            res->format,
+                            This->data, This->stride,
+                            0, /* depth = 1 */
+                            &box);
 
     return D3D_OK;
 }
index d43739bb2ada00ee0430f7e6a601b0f3eeea7097..8263060cd570b33f5647d0b3071142be411c60bb 100644 (file)
@@ -51,6 +51,8 @@ struct NineSurface9
     enum pipe_format format_conversion;
     unsigned stride; /* for system memory backing */
     unsigned stride_conversion;
+
+    unsigned pending_uploads_counter; /* pending uploads */
 };
 static inline struct NineSurface9 *
 NineSurface9( void *data )