st/nine: Optimize surface upload with conversion
authorAxel Davy <davyaxel0@gmail.com>
Wed, 10 Apr 2019 20:16:54 +0000 (22:16 +0200)
committerAxel Davy <davyaxel0@gmail.com>
Tue, 30 Apr 2019 17:18:50 +0000 (19:18 +0200)
Use nine_context_box_upload instead of locking the pipe
for surface upload with format conversion.
nine_context_box_upload already handles format
conversion.

Signed-off-by: Axel Davy <davyaxel0@gmail.com>
src/gallium/state_trackers/nine/surface9.c

index 7f4ecf559e823dca14d6b0987e590d076a64bf5d..f0bdf6372deed7880cf82e35468453b9cef0c784 100644 (file)
@@ -539,6 +539,7 @@ NineSurface9_LockRect( struct NineSurface9 *This,
 HRESULT NINE_WINAPI
 NineSurface9_UnlockRect( struct NineSurface9 *This )
 {
+    struct pipe_box dst_box, src_box;
     struct pipe_context *pipe;
     DBG("This=%p lock_count=%u\n", This, This->lock_count);
     user_assert(This->lock_count, D3DERR_INVALIDCALL);
@@ -551,35 +552,33 @@ NineSurface9_UnlockRect( struct NineSurface9 *This )
     --This->lock_count;
 
     if (This->data_conversion) {
-        struct pipe_transfer *transfer;
-        uint8_t *dst = This->data;
-        struct pipe_box box;
-
-        u_box_origin_2d(This->desc.Width, This->desc.Height, &box);
-
-        pipe = NineDevice9_GetPipe(This->base.base.device);
-        if (!dst) {
-            dst = pipe->transfer_map(pipe,
-                                     This->base.resource,
-                                     This->level,
-                                     PIPE_TRANSFER_WRITE |
-                                     PIPE_TRANSFER_DISCARD_WHOLE_RESOURCE,
-                                     &box, &transfer);
-            if (!dst)
-                return D3D_OK;
+        if (This->data) {
+            (void) util_format_translate(This->base.info.format,
+                                         This->data, This->stride,
+                                         0, 0,
+                                         This->format_conversion,
+                                         This->data_conversion,
+                                         This->stride_conversion,
+                                         0, 0,
+                                         This->desc.Width, This->desc.Height);
+        } else {
+            u_box_2d_zslice(0, 0, This->layer,
+                            This->desc.Width, This->desc.Height, &dst_box);
+            u_box_2d_zslice(0, 0, 0,
+                            This->desc.Width, This->desc.Height, &src_box);
+
+            nine_context_box_upload(This->base.base.device,
+                                    &This->pending_uploads_counter,
+                                    (struct NineUnknown *)This,
+                                    This->base.resource,
+                                    This->level,
+                                    &dst_box,
+                                    This->format_conversion,
+                                    This->data_conversion,
+                                    This->stride_conversion,
+                                    0, /* depth = 1 */
+                                    &src_box);
         }
-
-        (void) util_format_translate(This->base.info.format,
-                                     dst, This->data ? This->stride : transfer->stride,
-                                     0, 0,
-                                     This->format_conversion,
-                                     This->data_conversion,
-                                     This->stride_conversion,
-                                     0, 0,
-                                     This->desc.Width, This->desc.Height);
-
-        if (!This->data)
-            pipe_transfer_unmap(pipe, transfer);
     }
     return D3D_OK;
 }