st/nine: Fix leak with volume dtor
[mesa.git] / src / gallium / state_trackers / nine / volume9.c
index c46a9d1c2e03bf084000d0251cfd230a7f96c568..b579f9205f5a05f0556ca284e17f9a267e34e016 100644 (file)
 #include "device9.h"
 #include "volume9.h"
 #include "basetexture9.h" /* for marking dirty */
+#include "volumetexture9.h"
 #include "nine_helpers.h"
 #include "nine_pipe.h"
 #include "nine_dump.h"
 
-#include "util/u_hash_table.h"
 #include "util/u_format.h"
 #include "util/u_surface.h"
-#include "nine_pdata.h"
 
 #define DBG_CHANNEL DBG_VOLUME
 
@@ -43,7 +42,7 @@ NineVolume9_AllocateData( struct NineVolume9 *This )
     DBG("(%p(This=%p),level=%u) Allocating 0x%x bytes of system memory.\n",
         This->base.container, This, This->level, size);
 
-    This->data = (uint8_t *)MALLOC(size);
+    This->data = (uint8_t *)align_calloc(size, 32);
     if (!This->data)
         return E_OUTOFMEMORY;
     return D3D_OK;
@@ -76,13 +75,8 @@ NineVolume9_ctor( struct NineVolume9 *This,
     if (FAILED(hr))
         return hr;
 
-    This->pdata = util_hash_table_create(ht_guid_hash, ht_guid_compare);
-    if (!This->pdata)
-        return E_OUTOFMEMORY;
-
     pipe_resource_reference(&This->resource, pResource);
 
-    This->pipe = pParams->device->pipe;
     This->transfer = NULL;
     This->lock_count = 0;
 
@@ -92,7 +86,6 @@ NineVolume9_ctor( struct NineVolume9 *This,
 
     This->info.screen = pParams->device->screen;
     This->info.target = PIPE_TEXTURE_3D;
-    This->info.format = d3d9_to_pipe_format(pDesc->Format);
     This->info.width0 = pDesc->Width;
     This->info.height0 = pDesc->Height;
     This->info.depth0 = pDesc->Depth;
@@ -102,14 +95,39 @@ NineVolume9_ctor( struct NineVolume9 *This,
     This->info.usage = PIPE_USAGE_DEFAULT;
     This->info.bind = PIPE_BIND_SAMPLER_VIEW;
     This->info.flags = 0;
+    This->info.format = d3d9_to_pipe_format_checked(This->info.screen,
+                                                    pDesc->Format,
+                                                    This->info.target,
+                                                    This->info.nr_samples,
+                                                    This->info.bind, FALSE,
+                                                    pDesc->Pool == D3DPOOL_SCRATCH);
+
+    if (This->info.format == PIPE_FORMAT_NONE)
+        return D3DERR_DRIVERINTERNALERROR;
 
     This->stride = util_format_get_stride(This->info.format, pDesc->Width);
     This->stride = align(This->stride, 4);
     This->layer_stride = util_format_get_2d_size(This->info.format,
                                                  This->stride, pDesc->Height);
 
-    if (pDesc->Pool == D3DPOOL_SYSTEMMEM)
-        This->info.usage = PIPE_USAGE_STAGING;
+    /* Get true format */
+    This->format_conversion = d3d9_to_pipe_format_checked(This->info.screen,
+                                                         pDesc->Format,
+                                                         This->info.target,
+                                                         This->info.nr_samples,
+                                                         This->info.bind, FALSE,
+                                                         TRUE);
+    if (This->info.format != This->format_conversion) {
+        This->stride_conversion = nine_format_get_stride(This->format_conversion,
+                                                         pDesc->Width);
+        This->layer_stride_conversion = util_format_get_2d_size(This->format_conversion,
+                                                                This->stride_conversion,
+                                                                pDesc->Height);
+        This->data_conversion = align_calloc(This->layer_stride_conversion *
+                                             This->desc.Depth, 32);
+        if (!This->data_conversion)
+            return E_OUTOFMEMORY;
+    }
 
     if (!This->resource) {
         hr = NineVolume9_AllocateData(This);
@@ -127,22 +145,34 @@ NineVolume9_dtor( struct NineVolume9 *This )
     if (This->transfer)
         NineVolume9_UnlockBox(This);
 
+    if (This->data)
+        align_free(This->data);
+    if (This->data_conversion)
+        align_free(This->data_conversion);
+
     pipe_resource_reference(&This->resource, NULL);
 
     NineUnknown_dtor(&This->base);
 }
 
-HRESULT WINAPI
+HRESULT NINE_WINAPI
 NineVolume9_GetContainer( struct NineVolume9 *This,
                           REFIID riid,
                           void **ppContainer )
 {
+    char guid_str[64];
+
+    DBG("This=%p riid=%p id=%s ppContainer=%p\n",
+        This, riid, riid ? GUID_sprintf(guid_str, riid) : "", ppContainer);
+
+    (void)guid_str;
+
     if (!NineUnknown(This)->container)
         return E_NOINTERFACE;
     return NineUnknown_QueryInterface(NineUnknown(This)->container, riid, ppContainer);
 }
 
-static INLINE void
+static inline void
 NineVolume9_MarkContainerDirty( struct NineVolume9 *This )
 {
     struct NineBaseTexture9 *tex;
@@ -158,15 +188,12 @@ NineVolume9_MarkContainerDirty( struct NineVolume9 *This )
     tex = NineBaseTexture9(This->base.container);
     assert(tex);
     if (This->desc.Pool == D3DPOOL_MANAGED)
-        tex->dirty = TRUE;
-    else
-    if (This->desc.Usage & D3DUSAGE_AUTOGENMIPMAP)
-        tex->dirty_mip = TRUE;
+        tex->managed.dirty = TRUE;
 
     BASETEX_REGISTER_UPDATE(tex);
 }
 
-HRESULT WINAPI
+HRESULT NINE_WINAPI
 NineVolume9_GetDesc( struct NineVolume9 *This,
                      D3DVOLUME_DESC *pDesc )
 {
@@ -175,51 +202,27 @@ NineVolume9_GetDesc( struct NineVolume9 *This,
     return D3D_OK;
 }
 
-static INLINE boolean
-NineVolume9_IsDirty(struct NineVolume9 *This)
-{
-    return This->dirty_box[0].width != 0;
-}
-
-INLINE void
+inline void
 NineVolume9_AddDirtyRegion( struct NineVolume9 *This,
                             const struct pipe_box *box )
 {
-    struct pipe_box cover_a, cover_b;
-    float vol[2];
+    D3DBOX dirty_region;
+    struct NineVolumeTexture9 *tex = NineVolumeTexture9(This->base.container);
 
     if (!box) {
-        u_box_3d(0, 0, 0, This->desc.Width, This->desc.Height,
-                 This->desc.Depth, &This->dirty_box[0]);
-        memset(&This->dirty_box[1], 0, sizeof(This->dirty_box[1]));
-        return;
-    }
-    if (!This->dirty_box[0].width) {
-        This->dirty_box[0] = *box;
-        return;
-    }
-
-    u_box_union_3d(&cover_a, &This->dirty_box[0], box);
-    vol[0] = u_box_volume_3d(&cover_a);
-
-    if (This->dirty_box[1].width == 0) {
-        vol[1] = u_box_volume_3d(&This->dirty_box[0]);
-        if (vol[0] > (vol[1] * 1.5f))
-            This->dirty_box[1] = *box;
-        else
-            This->dirty_box[0] = cover_a;
+        NineVolumeTexture9_AddDirtyBox(tex, NULL);
     } else {
-        u_box_union_3d(&cover_b, &This->dirty_box[1], box);
-        vol[1] = u_box_volume_3d(&cover_b);
-
-        if (vol[0] > vol[1])
-            This->dirty_box[1] = cover_b;
-        else
-            This->dirty_box[0] = cover_a;
+        dirty_region.Left = box->x << This->level_actual;
+        dirty_region.Top = box->y << This->level_actual;
+        dirty_region.Front = box->z << This->level_actual;
+        dirty_region.Right = dirty_region.Left + (box->width << This->level_actual);
+        dirty_region.Bottom = dirty_region.Top + (box->height << This->level_actual);
+        dirty_region.Back = dirty_region.Front + (box->depth << This->level_actual);
+        NineVolumeTexture9_AddDirtyBox(tex, &dirty_region);
     }
 }
 
-static INLINE uint8_t *
+static inline uint8_t *
 NineVolume9_GetSystemMemPointer(struct NineVolume9 *This, int x, int y, int z)
 {
     unsigned x_offset = util_format_get_stride(This->info.format, x);
@@ -230,12 +233,13 @@ NineVolume9_GetSystemMemPointer(struct NineVolume9 *This, int x, int y, int z)
     return This->data + (z * This->layer_stride + y * This->stride + x_offset);
 }
 
-HRESULT WINAPI
+HRESULT NINE_WINAPI
 NineVolume9_LockBox( struct NineVolume9 *This,
                      D3DLOCKED_BOX *pLockedVolume,
                      const D3DBOX *pBox,
                      DWORD Flags )
 {
+    struct pipe_context *pipe;
     struct pipe_resource *resource = This->resource;
     struct pipe_box box;
     unsigned usage;
@@ -247,21 +251,26 @@ NineVolume9_LockBox( struct NineVolume9 *This,
         pBox ? pBox->Front : 0, pBox ? pBox->Back : 0,
         nine_D3DLOCK_to_str(Flags));
 
+    /* check if it's already locked */
+    user_assert(This->lock_count == 0, D3DERR_INVALIDCALL);
+
+    /* set pBits to NULL after lock_count check */
+    user_assert(pLockedVolume, E_POINTER);
+    pLockedVolume->pBits = NULL;
+
     user_assert(This->desc.Pool != D3DPOOL_DEFAULT ||
                 (This->desc.Usage & D3DUSAGE_DYNAMIC), D3DERR_INVALIDCALL);
 
     user_assert(!((Flags & D3DLOCK_DISCARD) && (Flags & D3DLOCK_READONLY)),
                 D3DERR_INVALIDCALL);
 
-    user_assert(This->lock_count == 0, D3DERR_INVALIDCALL);
-    user_assert(pLockedVolume, E_POINTER);
-
-    if (pBox && This->desc.Pool == D3DPOOL_DEFAULT &&
-        util_format_is_compressed(This->info.format)) {
+    if (pBox && compressed_format (This->desc.Format)) { /* For volume all pools are checked */
         const unsigned w = util_format_get_blockwidth(This->info.format);
         const unsigned h = util_format_get_blockheight(This->info.format);
-        user_assert(!(pBox->Left % w) && !(pBox->Right % w) &&
-                    !(pBox->Top % h) && !(pBox->Bottom % h),
+        user_assert((pBox->Left == 0 && pBox->Right == This->desc.Width &&
+                     pBox->Top == 0 && pBox->Bottom == This->desc.Height) ||
+                    (!(pBox->Left % w) && !(pBox->Right % w) &&
+                     !(pBox->Top % h) && !(pBox->Bottom % h)),
                     D3DERR_INVALIDCALL);
     }
 
@@ -275,6 +284,13 @@ NineVolume9_LockBox( struct NineVolume9 *This,
         usage |= PIPE_TRANSFER_DONTBLOCK;
 
     if (pBox) {
+        user_assert(pBox->Right > pBox->Left, D3DERR_INVALIDCALL);
+        user_assert(pBox->Bottom > pBox->Top, D3DERR_INVALIDCALL);
+        user_assert(pBox->Back > pBox->Front, D3DERR_INVALIDCALL);
+        user_assert(pBox->Right <= This->desc.Width, D3DERR_INVALIDCALL);
+        user_assert(pBox->Bottom <= This->desc.Height, D3DERR_INVALIDCALL);
+        user_assert(pBox->Back <= This->desc.Depth, D3DERR_INVALIDCALL);
+
         d3dbox_to_pipe_box(&box, pBox);
         if (u_box_clip_2d(&box, &box, This->desc.Width, This->desc.Height) < 0) {
             DBG("Locked volume intersection empty.\n");
@@ -285,15 +301,23 @@ NineVolume9_LockBox( struct NineVolume9 *This,
                  &box);
     }
 
-    if (This->data) {
+    if (This->data_conversion) {
+        /* For now we only have uncompressed formats here */
+        pLockedVolume->RowPitch = This->stride_conversion;
+        pLockedVolume->SlicePitch = This->layer_stride_conversion;
+        pLockedVolume->pBits = This->data_conversion + box.z * This->layer_stride_conversion +
+                               box.y * This->stride_conversion +
+                               util_format_get_stride(This->format_conversion, box.x);
+    } else if (This->data) {
         pLockedVolume->RowPitch = This->stride;
         pLockedVolume->SlicePitch = This->layer_stride;
         pLockedVolume->pBits =
             NineVolume9_GetSystemMemPointer(This, box.x, box.y, box.z);
     } else {
+        pipe = NineDevice9_GetPipe(This->base.device);
         pLockedVolume->pBits =
-            This->pipe->transfer_map(This->pipe, resource, This->level, usage,
-                                     &box, &This->transfer);
+            pipe->transfer_map(pipe, resource, This->level, usage,
+                               &box, &This->transfer);
         if (!This->transfer) {
             if (Flags & D3DLOCK_DONOTWAIT)
                 return D3DERR_WASSTILLDRAWING;
@@ -305,58 +329,93 @@ NineVolume9_LockBox( struct NineVolume9 *This,
 
     if (!(Flags & (D3DLOCK_NO_DIRTY_UPDATE | D3DLOCK_READONLY))) {
         NineVolume9_MarkContainerDirty(This);
-        if (This->desc.Pool == D3DPOOL_MANAGED)
-            NineVolume9_AddDirtyRegion(This, &box);
+        NineVolume9_AddDirtyRegion(This, &box);
     }
 
     ++This->lock_count;
     return D3D_OK;
 }
 
-HRESULT WINAPI
+HRESULT NINE_WINAPI
 NineVolume9_UnlockBox( struct NineVolume9 *This )
 {
+    struct pipe_context *pipe;
+
     DBG("This=%p lock_count=%u\n", This, This->lock_count);
     user_assert(This->lock_count, D3DERR_INVALIDCALL);
     if (This->transfer) {
-        This->pipe->transfer_unmap(This->pipe, This->transfer);
+        pipe = nine_context_get_pipe_acquire(This->base.device);
+        pipe->transfer_unmap(pipe, This->transfer);
         This->transfer = NULL;
+        nine_context_get_pipe_release(This->base.device);
     }
     --This->lock_count;
+
+    if (This->data_conversion) {
+        struct pipe_transfer *transfer;
+        uint8_t *dst = This->data;
+        struct pipe_box box;
+
+        u_box_3d(0, 0, 0, This->desc.Width, This->desc.Height, This->desc.Depth,
+                 &box);
+
+        pipe = NineDevice9_GetPipe(This->base.device);
+        if (!dst) {
+            dst = pipe->transfer_map(pipe,
+                                     This->resource,
+                                     This->level,
+                                     PIPE_TRANSFER_WRITE |
+                                     PIPE_TRANSFER_DISCARD_WHOLE_RESOURCE,
+                                     &box, &transfer);
+            if (!dst)
+                return D3D_OK;
+        }
+
+        (void) util_format_translate_3d(This->info.format,
+                                        dst, This->data ? This->stride : transfer->stride,
+                                        This->data ? This->layer_stride : transfer->layer_stride,
+                                        0, 0, 0,
+                                        This->format_conversion,
+                                        This->data_conversion,
+                                        This->stride_conversion,
+                                        This->layer_stride_conversion,
+                                        0, 0, 0,
+                                        This->desc.Width, This->desc.Height,
+                                        This->desc.Depth);
+
+        if (!This->data)
+            pipe_transfer_unmap(pipe, transfer);
+    }
+
     return D3D_OK;
 }
 
-
-HRESULT
-NineVolume9_CopyVolume( struct NineVolume9 *This,
-                        struct NineVolume9 *From,
-                        unsigned dstx, unsigned dsty, unsigned dstz,
-                        struct pipe_box *pSrcBox )
+/* When this function is called, we have already checked
+ * The copy regions fit the volumes */
+void
+NineVolume9_CopyMemToDefault( struct NineVolume9 *This,
+                              struct NineVolume9 *From,
+                              unsigned dstx, unsigned dsty, unsigned dstz,
+                              struct pipe_box *pSrcBox )
 {
-    struct pipe_context *pipe = This->pipe;
+    struct pipe_context *pipe;
+    struct pipe_transfer *transfer = NULL;
     struct pipe_resource *r_dst = This->resource;
-    struct pipe_resource *r_src = From->resource;
-    struct pipe_transfer *transfer;
     struct pipe_box src_box;
     struct pipe_box dst_box;
-    uint8_t *p_dst;
-    const uint8_t *p_src;
+    uint8_t *map = NULL;
+
+    DBG("This=%p From=%p dstx=%u dsty=%u dstz=%u pSrcBox=%p\n",
+        This, From, dstx, dsty, dstz, pSrcBox);
 
-    user_assert(This->desc.Format == From->desc.Format, D3DERR_INVALIDCALL);
+    assert(This->desc.Pool == D3DPOOL_DEFAULT &&
+           From->desc.Pool == D3DPOOL_SYSTEMMEM);
 
     dst_box.x = dstx;
     dst_box.y = dsty;
     dst_box.z = dstz;
 
     if (pSrcBox) {
-        /* make sure it doesn't range outside the source volume */
-        user_assert(pSrcBox->x >= 0 &&
-                    (pSrcBox->width - pSrcBox->x) <= From->desc.Width &&
-                    pSrcBox->y >= 0 &&
-                    (pSrcBox->height - pSrcBox->y) <= From->desc.Height &&
-                    pSrcBox->z >= 0 &&
-                    (pSrcBox->depth - pSrcBox->z) <= From->desc.Depth,
-                    D3DERR_INVALIDCALL);
         src_box = *pSrcBox;
     } else {
         src_box.x = 0;
@@ -366,116 +425,89 @@ NineVolume9_CopyVolume( struct NineVolume9 *This,
         src_box.height = From->desc.Height;
         src_box.depth = From->desc.Depth;
     }
-    /* limits */
-    dst_box.width = This->desc.Width - dst_box.x;
-    dst_box.height = This->desc.Height - dst_box.y;
-    dst_box.depth = This->desc.Depth - dst_box.z;
-
-    user_assert(src_box.width <= dst_box.width &&
-                src_box.height <= dst_box.height &&
-                src_box.depth <= dst_box.depth, D3DERR_INVALIDCALL);
 
     dst_box.width = src_box.width;
     dst_box.height = src_box.height;
     dst_box.depth = src_box.depth;
 
-    /* Don't copy to device memory of managed resources.
-     * We don't want to download it back again later.
-     */
-    if (This->desc.Pool == D3DPOOL_MANAGED)
-        r_dst = NULL;
-
-    /* Don't copy from stale device memory of managed resources.
-     * Also, don't copy between system and device if we don't have to.
-     */
-    if (From->desc.Pool == D3DPOOL_MANAGED) {
-        if (!r_dst || NineVolume9_IsDirty(From))
-            r_src = NULL;
-    }
-
-    if (r_dst && r_src) {
-        pipe->resource_copy_region(pipe,
-                                   r_dst, This->level,
-                                   dst_box.x, dst_box.y, dst_box.z,
-                                   r_src, From->level,
-                                   &src_box);
-    } else
-    if (r_dst) {
-        p_src = NineVolume9_GetSystemMemPointer(From,
-            src_box.x, src_box.y, src_box.z);
-
-        pipe->transfer_inline_write(pipe, r_dst, This->level,
-                                    0, /* WRITE|DISCARD are implicit */
-                                    &dst_box, p_src,
-                                    From->stride, From->layer_stride);
-    } else
-    if (r_src) {
-        p_dst = NineVolume9_GetSystemMemPointer(This, 0, 0, 0);
-        p_src = pipe->transfer_map(pipe, r_src, From->level,
-                                   PIPE_TRANSFER_READ,
-                                   &src_box, &transfer);
-        if (!p_src)
-            return D3DERR_DRIVERINTERNALERROR;
-
-        util_copy_box(p_dst, This->info.format,
-                      This->stride, This->layer_stride,
-                      dst_box.x, dst_box.y, dst_box.z,
-                      dst_box.width, dst_box.height, dst_box.depth,
-                      p_src,
-                      transfer->stride, transfer->layer_stride,
-                      src_box.x, src_box.y, src_box.z);
-
-        pipe->transfer_unmap(pipe, transfer);
-    } else {
-        p_dst = NineVolume9_GetSystemMemPointer(This, 0, 0, 0);
-        p_src = NineVolume9_GetSystemMemPointer(From, 0, 0, 0);
-
-        util_copy_box(p_dst, This->info.format,
-                      This->stride, This->layer_stride,
-                      dst_box.x, dst_box.y, dst_box.z,
-                      dst_box.width, dst_box.height, dst_box.depth,
-                      p_src,
-                      From->stride, From->layer_stride,
-                      src_box.x, src_box.y, src_box.z);
-    }
+    pipe = NineDevice9_GetPipe(This->base.device);
 
-    if (This->desc.Pool == D3DPOOL_DEFAULT ||
-        This->desc.Pool == D3DPOOL_MANAGED)
-        NineVolume9_MarkContainerDirty(This);
-    if (!r_dst && This->resource)
-        NineVolume9_AddDirtyRegion(This, &dst_box);
+    map = pipe->transfer_map(pipe,
+                             r_dst,
+                             This->level,
+                             PIPE_TRANSFER_WRITE | PIPE_TRANSFER_DISCARD_RANGE,
+                             &dst_box, &transfer);
+    if (!map)
+        return;
 
-    return D3D_OK;
+    /* Note: if formats are the sames, it will revert
+     * to normal memcpy */
+    (void) util_format_translate_3d(r_dst->format,
+                                    map, transfer->stride,
+                                    transfer->layer_stride,
+                                    0, 0, 0,
+                                    From->info.format,
+                                    From->data, From->stride,
+                                    From->layer_stride,
+                                    src_box.x, src_box.y,
+                                    src_box.z,
+                                    src_box.width,
+                                    src_box.height,
+                                    src_box.depth);
+
+    pipe_transfer_unmap(pipe, transfer);
+
+    if (This->data_conversion)
+        (void) util_format_translate_3d(This->format_conversion,
+                                        This->data_conversion,
+                                        This->stride_conversion,
+                                        This->layer_stride_conversion,
+                                        dstx, dsty, dstz,
+                                        From->info.format,
+                                        From->data, From->stride,
+                                        From->layer_stride,
+                                        src_box.x, src_box.y,
+                                        src_box.z,
+                                        src_box.width,
+                                        src_box.height,
+                                        src_box.depth);
+
+    NineVolume9_MarkContainerDirty(This);
+
+    return;
 }
 
 HRESULT
-NineVolume9_UploadSelf( struct NineVolume9 *This )
+NineVolume9_UploadSelf( struct NineVolume9 *This,
+                        const struct pipe_box *damaged )
 {
-    struct pipe_context *pipe = This->pipe;
+    struct pipe_context *pipe;
     struct pipe_resource *res = This->resource;
+    struct pipe_box box;
     uint8_t *ptr;
-    unsigned i;
 
-    DBG("This=%p dirty=%i data=%p res=%p\n", This, NineVolume9_IsDirty(This),
+    DBG("This=%p damaged=%p data=%p res=%p\n", This, damaged,
         This->data, res);
 
     assert(This->desc.Pool == D3DPOOL_MANAGED);
-
-    if (!NineVolume9_IsDirty(This))
-        return D3D_OK;
     assert(res);
 
-    for (i = 0; i < Elements(This->dirty_box); ++i) {
-        const struct pipe_box *box = &This->dirty_box[i];
-        if (box->width == 0)
-            break;
-        ptr = NineVolume9_GetSystemMemPointer(This, box->x, box->y, box->z);
-
-        pipe->transfer_inline_write(pipe, res, This->level,
-                                    0,
-                                    box, ptr, This->stride, This->layer_stride);
+    if (damaged) {
+        box = *damaged;
+    } else {
+        box.x = 0;
+        box.y = 0;
+        box.z = 0;
+        box.width = This->desc.Width;
+        box.height = This->desc.Height;
+        box.depth = This->desc.Depth;
     }
-    NineVolume9_ClearDirtyRegion(This);
+
+    ptr = NineVolume9_GetSystemMemPointer(This, box.x, box.y, box.z);
+
+    pipe = NineDevice9_GetPipe(This->base.device);
+    pipe->texture_subdata(pipe, res, This->level, 0, &box,
+                          ptr, This->stride, This->layer_stride);
 
     return D3D_OK;
 }
@@ -486,9 +518,9 @@ IDirect3DVolume9Vtbl NineVolume9_vtable = {
     (void *)NineUnknown_AddRef,
     (void *)NineUnknown_Release,
     (void *)NineUnknown_GetDevice, /* actually part of Volume9 iface */
-    (void *)NineVolume9_SetPrivateData,
-    (void *)NineVolume9_GetPrivateData,
-    (void *)NineVolume9_FreePrivateData,
+    (void *)NineUnknown_SetPrivateData,
+    (void *)NineUnknown_GetPrivateData,
+    (void *)NineUnknown_FreePrivateData,
     (void *)NineVolume9_GetContainer,
     (void *)NineVolume9_GetDesc,
     (void *)NineVolume9_LockBox,
@@ -512,93 +544,3 @@ NineVolume9_new( struct NineDevice9 *pDevice,
     NINE_DEVICE_CHILD_NEW(Volume9, ppOut, pDevice, /* args */
                           pContainer, pResource, Level, pDesc);
 }
-
-
-/*** The boring stuff. TODO: Unify with Resource. ***/
-
-HRESULT WINAPI
-NineVolume9_SetPrivateData( struct NineVolume9 *This,
-                            REFGUID refguid,
-                            const void *pData,
-                            DWORD SizeOfData,
-                            DWORD Flags )
-{
-    enum pipe_error err;
-    struct pheader *header;
-    const void *user_data = pData;
-
-    if (Flags & D3DSPD_IUNKNOWN)
-        user_assert(SizeOfData == sizeof(IUnknown *), D3DERR_INVALIDCALL);
-
-    /* data consists of a header and the actual data. avoiding 2 mallocs */
-    header = CALLOC_VARIANT_LENGTH_STRUCT(pheader, SizeOfData-1);
-    if (!header) { return E_OUTOFMEMORY; }
-    header->unknown = (Flags & D3DSPD_IUNKNOWN) ? TRUE : FALSE;
-
-    /* if the refguid already exists, delete it */
-    NineVolume9_FreePrivateData(This, refguid);
-
-    /* IUnknown special case */
-    if (header->unknown) {
-        /* here the pointer doesn't point to the data we want, so point at the
-         * pointer making what we eventually copy is the pointer itself */
-        user_data = &pData;
-    }
-
-    header->size = SizeOfData;
-    memcpy(header->data, user_data, header->size);
-
-    err = util_hash_table_set(This->pdata, refguid, header);
-    if (err == PIPE_OK) {
-        if (header->unknown) { IUnknown_AddRef(*(IUnknown **)header->data); }
-        return D3D_OK;
-    }
-
-    FREE(header);
-    if (err == PIPE_ERROR_OUT_OF_MEMORY) { return E_OUTOFMEMORY; }
-
-    return D3DERR_DRIVERINTERNALERROR;
-}
-
-HRESULT WINAPI
-NineVolume9_GetPrivateData( struct NineVolume9 *This,
-                            REFGUID refguid,
-                            void *pData,
-                            DWORD *pSizeOfData )
-{
-    struct pheader *header;
-
-    user_assert(pSizeOfData, E_POINTER);
-
-    header = util_hash_table_get(This->pdata, refguid);
-    if (!header) { return D3DERR_NOTFOUND; }
-
-    if (!pData) {
-        *pSizeOfData = header->size;
-        return D3D_OK;
-    }
-    if (*pSizeOfData < header->size) {
-        return D3DERR_MOREDATA;
-    }
-
-    if (header->unknown) { IUnknown_AddRef(*(IUnknown **)header->data); }
-    memcpy(pData, header->data, header->size);
-
-    return D3D_OK;
-}
-
-HRESULT WINAPI
-NineVolume9_FreePrivateData( struct NineVolume9 *This,
-                             REFGUID refguid )
-{
-    struct pheader *header;
-
-    header = util_hash_table_get(This->pdata, refguid);
-    if (!header) { return D3DERR_NOTFOUND; }
-
-    ht_guid_delete(NULL, header, NULL);
-    util_hash_table_remove(This->pdata, refguid);
-
-    return D3D_OK;
-}
-