st/nine: Fix volumetexture dtor on ctor failure
[mesa.git] / src / gallium / state_trackers / nine / volume9.c
index 29a1fcbbd03a7155942c2490948668a7c20df451..ec811aeba13db456f8dccb5a810cfcd5a55b5372 100644 (file)
@@ -92,6 +92,7 @@ NineVolume9_ctor( struct NineVolume9 *This,
     This->info.last_level = 0;
     This->info.array_size = 1;
     This->info.nr_samples = 0;
+    This->info.nr_storage_samples = 0;
     This->info.usage = PIPE_USAGE_DEFAULT;
     This->info.bind = PIPE_BIND_SAMPLER_VIEW;
     This->info.flags = 0;
@@ -142,9 +143,15 @@ NineVolume9_dtor( struct NineVolume9 *This )
 {
     DBG("This=%p\n", This);
 
-    if (This->transfer)
-        NineVolume9_UnlockBox(This);
+    if (This->transfer) {
+        struct pipe_context *pipe = nine_context_get_pipe_multithread(This->base.device);
+        pipe->transfer_unmap(pipe, This->transfer);
+        This->transfer = NULL;
+    }
 
+    /* Note: Following condition cannot happen currently, since we
+     * refcount the volume in the functions increasing
+     * pending_uploads_counter. */
     if (p_atomic_read(&This->pending_uploads_counter))
         nine_csmt_process(This->base.device);
 
@@ -320,10 +327,17 @@ NineVolume9_LockBox( struct NineVolume9 *This,
         pLockedVolume->pBits =
             NineVolume9_GetSystemMemPointer(This, box.x, box.y, box.z);
     } else {
-        pipe = NineDevice9_GetPipe(This->base.device);
+        bool no_refs = !p_atomic_read(&This->base.bind) &&
+            !p_atomic_read(&This->base.container->bind);
+        if (no_refs)
+            pipe = nine_context_get_pipe_acquire(This->base.device);
+        else
+            pipe = NineDevice9_GetPipe(This->base.device);
         pLockedVolume->pBits =
             pipe->transfer_map(pipe, resource, This->level, usage,
                                &box, &This->transfer);
+        if (no_refs)
+            nine_context_get_pipe_release(This->base.device);
         if (!This->transfer) {
             if (Flags & D3DLOCK_DONOTWAIT)
                 return D3DERR_WASSTILLDRAWING;