Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Last modification | View Log | RSS feed

  1. /*
  2.  * Copyright 2011 Joakim Sindholt <opensource@zhasha.com>
  3.  *
  4.  * Permission is hereby granted, free of charge, to any person obtaining a
  5.  * copy of this software and associated documentation files (the "Software"),
  6.  * to deal in the Software without restriction, including without limitation
  7.  * on the rights to use, copy, modify, merge, publish, distribute, sub
  8.  * license, and/or sell copies of the Software, and to permit persons to whom
  9.  * the Software is furnished to do so, subject to the following conditions:
  10.  *
  11.  * The above copyright notice and this permission notice (including the next
  12.  * paragraph) shall be included in all copies or substantial portions of the
  13.  * Software.
  14.  *
  15.  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16.  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17.  * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
  18.  * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
  19.  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  20.  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  21.  * USE OR OTHER DEALINGS IN THE SOFTWARE. */
  22.  
  23. #include "device9.h"
  24. #include "volume9.h"
  25. #include "basetexture9.h" /* for marking dirty */
  26. #include "nine_helpers.h"
  27. #include "nine_pipe.h"
  28. #include "nine_dump.h"
  29.  
  30. #include "util/u_hash_table.h"
  31. #include "util/u_format.h"
  32. #include "util/u_surface.h"
  33. #include "nine_pdata.h"
  34.  
  35. #define DBG_CHANNEL DBG_VOLUME
  36.  
  37.  
  38. static HRESULT
  39. NineVolume9_AllocateData( struct NineVolume9 *This )
  40. {
  41.     unsigned size = This->layer_stride * This->desc.Depth;
  42.  
  43.     DBG("(%p(This=%p),level=%u) Allocating 0x%x bytes of system memory.\n",
  44.         This->base.container, This, This->level, size);
  45.  
  46.     This->data = (uint8_t *)MALLOC(size);
  47.     if (!This->data)
  48.         return E_OUTOFMEMORY;
  49.     return D3D_OK;
  50. }
  51.  
  52. static HRESULT
  53. NineVolume9_ctor( struct NineVolume9 *This,
  54.                   struct NineUnknownParams *pParams,
  55.                   struct NineUnknown *pContainer,
  56.                   struct pipe_resource *pResource,
  57.                   unsigned Level,
  58.                   D3DVOLUME_DESC *pDesc )
  59. {
  60.     HRESULT hr;
  61.  
  62.     assert(pContainer); /* stand-alone volumes can't be created */
  63.  
  64.     DBG("This=%p pContainer=%p pDevice=%p pResource=%p Level=%u pDesc=%p\n",
  65.         This, pContainer, pParams->device, pResource, Level, pDesc);
  66.  
  67.     /* Mark this as a special surface held by another internal resource. */
  68.     pParams->container = pContainer;
  69.  
  70.     user_assert(!(pDesc->Usage & D3DUSAGE_DYNAMIC) ||
  71.                 (pDesc->Pool != D3DPOOL_MANAGED), D3DERR_INVALIDCALL);
  72.  
  73.     assert(pResource || pDesc->Pool != D3DPOOL_DEFAULT);
  74.  
  75.     hr = NineUnknown_ctor(&This->base, pParams);
  76.     if (FAILED(hr))
  77.         return hr;
  78.  
  79.     This->pdata = util_hash_table_create(ht_guid_hash, ht_guid_compare);
  80.     if (!This->pdata)
  81.         return E_OUTOFMEMORY;
  82.  
  83.     pipe_resource_reference(&This->resource, pResource);
  84.  
  85.     This->pipe = pParams->device->pipe;
  86.     This->transfer = NULL;
  87.     This->lock_count = 0;
  88.  
  89.     This->level = Level;
  90.     This->level_actual = Level;
  91.     This->desc = *pDesc;
  92.  
  93.     This->info.screen = pParams->device->screen;
  94.     This->info.target = PIPE_TEXTURE_3D;
  95.     This->info.width0 = pDesc->Width;
  96.     This->info.height0 = pDesc->Height;
  97.     This->info.depth0 = pDesc->Depth;
  98.     This->info.last_level = 0;
  99.     This->info.array_size = 1;
  100.     This->info.nr_samples = 0;
  101.     This->info.usage = PIPE_USAGE_DEFAULT;
  102.     This->info.bind = PIPE_BIND_SAMPLER_VIEW;
  103.     This->info.flags = 0;
  104.     This->info.format = d3d9_to_pipe_format_checked(This->info.screen,
  105.                                                     pDesc->Format,
  106.                                                     This->info.target,
  107.                                                     This->info.nr_samples,
  108.                                                     This->info.bind, FALSE);
  109.  
  110.     if (This->info.format == PIPE_FORMAT_NONE)
  111.         return D3DERR_DRIVERINTERNALERROR;
  112.  
  113.     This->stride = util_format_get_stride(This->info.format, pDesc->Width);
  114.     This->stride = align(This->stride, 4);
  115.     This->layer_stride = util_format_get_2d_size(This->info.format,
  116.                                                  This->stride, pDesc->Height);
  117.  
  118.     if (pDesc->Pool == D3DPOOL_SYSTEMMEM)
  119.         This->info.usage = PIPE_USAGE_STAGING;
  120.  
  121.     if (!This->resource) {
  122.         hr = NineVolume9_AllocateData(This);
  123.         if (FAILED(hr))
  124.             return hr;
  125.     }
  126.     return D3D_OK;
  127. }
  128.  
  129. static void
  130. NineVolume9_dtor( struct NineVolume9 *This )
  131. {
  132.     DBG("This=%p\n", This);
  133.  
  134.     if (This->transfer)
  135.         NineVolume9_UnlockBox(This);
  136.  
  137.     if (This->data)
  138.            FREE(This->data);
  139.  
  140.     pipe_resource_reference(&This->resource, NULL);
  141.  
  142.     NineUnknown_dtor(&This->base);
  143. }
  144.  
  145. HRESULT WINAPI
  146. NineVolume9_GetContainer( struct NineVolume9 *This,
  147.                           REFIID riid,
  148.                           void **ppContainer )
  149. {
  150.     if (!NineUnknown(This)->container)
  151.         return E_NOINTERFACE;
  152.     return NineUnknown_QueryInterface(NineUnknown(This)->container, riid, ppContainer);
  153. }
  154.  
  155. static INLINE void
  156. NineVolume9_MarkContainerDirty( struct NineVolume9 *This )
  157. {
  158.     struct NineBaseTexture9 *tex;
  159. #ifdef DEBUG
  160.     /* This is always contained by a NineVolumeTexture9. */
  161.     GUID id = IID_IDirect3DVolumeTexture9;
  162.     REFIID ref = &id;
  163.     assert(NineUnknown_QueryInterface(This->base.container, ref, (void **)&tex)
  164.            == S_OK);
  165.     assert(NineUnknown_Release(NineUnknown(tex)) != 0);
  166. #endif
  167.  
  168.     tex = NineBaseTexture9(This->base.container);
  169.     assert(tex);
  170.     if (This->desc.Pool == D3DPOOL_MANAGED)
  171.         tex->managed.dirty = TRUE;
  172.  
  173.     BASETEX_REGISTER_UPDATE(tex);
  174. }
  175.  
  176. HRESULT WINAPI
  177. NineVolume9_GetDesc( struct NineVolume9 *This,
  178.                      D3DVOLUME_DESC *pDesc )
  179. {
  180.     user_assert(pDesc != NULL, E_POINTER);
  181.     *pDesc = This->desc;
  182.     return D3D_OK;
  183. }
  184.  
  185. static INLINE boolean
  186. NineVolume9_IsDirty(struct NineVolume9 *This)
  187. {
  188.     return This->dirty_box[0].width != 0;
  189. }
  190.  
  191. INLINE void
  192. NineVolume9_AddDirtyRegion( struct NineVolume9 *This,
  193.                             const struct pipe_box *box )
  194. {
  195.     struct pipe_box cover_a, cover_b;
  196.     float vol[2];
  197.  
  198.     if (!box) {
  199.         u_box_3d(0, 0, 0, This->desc.Width, This->desc.Height,
  200.                  This->desc.Depth, &This->dirty_box[0]);
  201.         memset(&This->dirty_box[1], 0, sizeof(This->dirty_box[1]));
  202.         return;
  203.     }
  204.     if (!This->dirty_box[0].width) {
  205.         This->dirty_box[0] = *box;
  206.         return;
  207.     }
  208.  
  209.     u_box_union_3d(&cover_a, &This->dirty_box[0], box);
  210.     vol[0] = u_box_volume_3d(&cover_a);
  211.  
  212.     if (This->dirty_box[1].width == 0) {
  213.         vol[1] = u_box_volume_3d(&This->dirty_box[0]);
  214.         if (vol[0] > (vol[1] * 1.5f))
  215.             This->dirty_box[1] = *box;
  216.         else
  217.             This->dirty_box[0] = cover_a;
  218.     } else {
  219.         u_box_union_3d(&cover_b, &This->dirty_box[1], box);
  220.         vol[1] = u_box_volume_3d(&cover_b);
  221.  
  222.         if (vol[0] > vol[1])
  223.             This->dirty_box[1] = cover_b;
  224.         else
  225.             This->dirty_box[0] = cover_a;
  226.     }
  227. }
  228.  
  229. static INLINE uint8_t *
  230. NineVolume9_GetSystemMemPointer(struct NineVolume9 *This, int x, int y, int z)
  231. {
  232.     unsigned x_offset = util_format_get_stride(This->info.format, x);
  233.  
  234.     y = util_format_get_nblocksy(This->info.format, y);
  235.  
  236.     assert(This->data);
  237.     return This->data + (z * This->layer_stride + y * This->stride + x_offset);
  238. }
  239.  
  240. HRESULT WINAPI
  241. NineVolume9_LockBox( struct NineVolume9 *This,
  242.                      D3DLOCKED_BOX *pLockedVolume,
  243.                      const D3DBOX *pBox,
  244.                      DWORD Flags )
  245. {
  246.     struct pipe_resource *resource = This->resource;
  247.     struct pipe_box box;
  248.     unsigned usage;
  249.  
  250.     DBG("This=%p(%p) pLockedVolume=%p pBox=%p[%u..%u,%u..%u,%u..%u] Flags=%s\n",
  251.         This, This->base.container, pLockedVolume, pBox,
  252.         pBox ? pBox->Left : 0, pBox ? pBox->Right : 0,
  253.         pBox ? pBox->Top : 0, pBox ? pBox->Bottom : 0,
  254.         pBox ? pBox->Front : 0, pBox ? pBox->Back : 0,
  255.         nine_D3DLOCK_to_str(Flags));
  256.  
  257.     user_assert(This->desc.Pool != D3DPOOL_DEFAULT ||
  258.                 (This->desc.Usage & D3DUSAGE_DYNAMIC), D3DERR_INVALIDCALL);
  259.  
  260.     user_assert(!((Flags & D3DLOCK_DISCARD) && (Flags & D3DLOCK_READONLY)),
  261.                 D3DERR_INVALIDCALL);
  262.  
  263.     user_assert(This->lock_count == 0, D3DERR_INVALIDCALL);
  264.     user_assert(pLockedVolume, E_POINTER);
  265.  
  266.     if (pBox && This->desc.Pool == D3DPOOL_DEFAULT &&
  267.         util_format_is_compressed(This->info.format)) {
  268.         const unsigned w = util_format_get_blockwidth(This->info.format);
  269.         const unsigned h = util_format_get_blockheight(This->info.format);
  270.         user_assert(!(pBox->Left % w) && !(pBox->Right % w) &&
  271.                     !(pBox->Top % h) && !(pBox->Bottom % h),
  272.                     D3DERR_INVALIDCALL);
  273.     }
  274.  
  275.     if (Flags & D3DLOCK_DISCARD) {
  276.         usage = PIPE_TRANSFER_WRITE | PIPE_TRANSFER_DISCARD_RANGE;
  277.     } else {
  278.         usage = (Flags & D3DLOCK_READONLY) ?
  279.             PIPE_TRANSFER_READ : PIPE_TRANSFER_READ_WRITE;
  280.     }
  281.     if (Flags & D3DLOCK_DONOTWAIT)
  282.         usage |= PIPE_TRANSFER_DONTBLOCK;
  283.  
  284.     if (pBox) {
  285.         d3dbox_to_pipe_box(&box, pBox);
  286.         if (u_box_clip_2d(&box, &box, This->desc.Width, This->desc.Height) < 0) {
  287.             DBG("Locked volume intersection empty.\n");
  288.             return D3DERR_INVALIDCALL;
  289.         }
  290.     } else {
  291.         u_box_3d(0, 0, 0, This->desc.Width, This->desc.Height, This->desc.Depth,
  292.                  &box);
  293.     }
  294.  
  295.     if (This->data) {
  296.         pLockedVolume->RowPitch = This->stride;
  297.         pLockedVolume->SlicePitch = This->layer_stride;
  298.         pLockedVolume->pBits =
  299.             NineVolume9_GetSystemMemPointer(This, box.x, box.y, box.z);
  300.     } else {
  301.         pLockedVolume->pBits =
  302.             This->pipe->transfer_map(This->pipe, resource, This->level, usage,
  303.                                      &box, &This->transfer);
  304.         if (!This->transfer) {
  305.             if (Flags & D3DLOCK_DONOTWAIT)
  306.                 return D3DERR_WASSTILLDRAWING;
  307.             return D3DERR_DRIVERINTERNALERROR;
  308.         }
  309.         pLockedVolume->RowPitch = This->transfer->stride;
  310.         pLockedVolume->SlicePitch = This->transfer->layer_stride;
  311.     }
  312.  
  313.     if (!(Flags & (D3DLOCK_NO_DIRTY_UPDATE | D3DLOCK_READONLY))) {
  314.         NineVolume9_MarkContainerDirty(This);
  315.         if (This->desc.Pool == D3DPOOL_MANAGED)
  316.             NineVolume9_AddDirtyRegion(This, &box);
  317.     }
  318.  
  319.     ++This->lock_count;
  320.     return D3D_OK;
  321. }
  322.  
  323. HRESULT WINAPI
  324. NineVolume9_UnlockBox( struct NineVolume9 *This )
  325. {
  326.     DBG("This=%p lock_count=%u\n", This, This->lock_count);
  327.     user_assert(This->lock_count, D3DERR_INVALIDCALL);
  328.     if (This->transfer) {
  329.         This->pipe->transfer_unmap(This->pipe, This->transfer);
  330.         This->transfer = NULL;
  331.     }
  332.     --This->lock_count;
  333.     return D3D_OK;
  334. }
  335.  
  336.  
  337. HRESULT
  338. NineVolume9_CopyVolume( struct NineVolume9 *This,
  339.                         struct NineVolume9 *From,
  340.                         unsigned dstx, unsigned dsty, unsigned dstz,
  341.                         struct pipe_box *pSrcBox )
  342. {
  343.     struct pipe_context *pipe = This->pipe;
  344.     struct pipe_resource *r_dst = This->resource;
  345.     struct pipe_resource *r_src = From->resource;
  346.     struct pipe_transfer *transfer;
  347.     struct pipe_box src_box;
  348.     struct pipe_box dst_box;
  349.     uint8_t *p_dst;
  350.     const uint8_t *p_src;
  351.  
  352.     DBG("This=%p From=%p dstx=%u dsty=%u dstz=%u pSrcBox=%p\n",
  353.         This, From, dstx, dsty, dstz, pSrcBox);
  354.  
  355.     assert(This->desc.Pool != D3DPOOL_MANAGED &&
  356.            From->desc.Pool != D3DPOOL_MANAGED);
  357.     user_assert(This->desc.Format == From->desc.Format, D3DERR_INVALIDCALL);
  358.  
  359.     dst_box.x = dstx;
  360.     dst_box.y = dsty;
  361.     dst_box.z = dstz;
  362.  
  363.     if (pSrcBox) {
  364.         /* make sure it doesn't range outside the source volume */
  365.         user_assert(pSrcBox->x >= 0 &&
  366.                     (pSrcBox->width - pSrcBox->x) <= From->desc.Width &&
  367.                     pSrcBox->y >= 0 &&
  368.                     (pSrcBox->height - pSrcBox->y) <= From->desc.Height &&
  369.                     pSrcBox->z >= 0 &&
  370.                     (pSrcBox->depth - pSrcBox->z) <= From->desc.Depth,
  371.                     D3DERR_INVALIDCALL);
  372.         src_box = *pSrcBox;
  373.     } else {
  374.         src_box.x = 0;
  375.         src_box.y = 0;
  376.         src_box.z = 0;
  377.         src_box.width = From->desc.Width;
  378.         src_box.height = From->desc.Height;
  379.         src_box.depth = From->desc.Depth;
  380.     }
  381.     /* limits */
  382.     dst_box.width = This->desc.Width - dst_box.x;
  383.     dst_box.height = This->desc.Height - dst_box.y;
  384.     dst_box.depth = This->desc.Depth - dst_box.z;
  385.  
  386.     user_assert(src_box.width <= dst_box.width &&
  387.                 src_box.height <= dst_box.height &&
  388.                 src_box.depth <= dst_box.depth, D3DERR_INVALIDCALL);
  389.  
  390.     dst_box.width = src_box.width;
  391.     dst_box.height = src_box.height;
  392.     dst_box.depth = src_box.depth;
  393.  
  394.     if (r_dst && r_src) {
  395.         pipe->resource_copy_region(pipe,
  396.                                    r_dst, This->level,
  397.                                    dst_box.x, dst_box.y, dst_box.z,
  398.                                    r_src, From->level,
  399.                                    &src_box);
  400.     } else
  401.     if (r_dst) {
  402.         p_src = NineVolume9_GetSystemMemPointer(From,
  403.             src_box.x, src_box.y, src_box.z);
  404.  
  405.         pipe->transfer_inline_write(pipe, r_dst, This->level,
  406.                                     0, /* WRITE|DISCARD are implicit */
  407.                                     &dst_box, p_src,
  408.                                     From->stride, From->layer_stride);
  409.     } else
  410.     if (r_src) {
  411.         p_dst = NineVolume9_GetSystemMemPointer(This, 0, 0, 0);
  412.         p_src = pipe->transfer_map(pipe, r_src, From->level,
  413.                                    PIPE_TRANSFER_READ,
  414.                                    &src_box, &transfer);
  415.         if (!p_src)
  416.             return D3DERR_DRIVERINTERNALERROR;
  417.  
  418.         util_copy_box(p_dst, This->info.format,
  419.                       This->stride, This->layer_stride,
  420.                       dst_box.x, dst_box.y, dst_box.z,
  421.                       dst_box.width, dst_box.height, dst_box.depth,
  422.                       p_src,
  423.                       transfer->stride, transfer->layer_stride,
  424.                       src_box.x, src_box.y, src_box.z);
  425.  
  426.         pipe->transfer_unmap(pipe, transfer);
  427.     } else {
  428.         p_dst = NineVolume9_GetSystemMemPointer(This, 0, 0, 0);
  429.         p_src = NineVolume9_GetSystemMemPointer(From, 0, 0, 0);
  430.  
  431.         util_copy_box(p_dst, This->info.format,
  432.                       This->stride, This->layer_stride,
  433.                       dst_box.x, dst_box.y, dst_box.z,
  434.                       dst_box.width, dst_box.height, dst_box.depth,
  435.                       p_src,
  436.                       From->stride, From->layer_stride,
  437.                       src_box.x, src_box.y, src_box.z);
  438.     }
  439.  
  440.     if (This->desc.Pool == D3DPOOL_DEFAULT)
  441.         NineVolume9_MarkContainerDirty(This);
  442.     if (!r_dst && This->resource)
  443.         NineVolume9_AddDirtyRegion(This, &dst_box);
  444.  
  445.     return D3D_OK;
  446. }
  447.  
  448. HRESULT
  449. NineVolume9_UploadSelf( struct NineVolume9 *This )
  450. {
  451.     struct pipe_context *pipe = This->pipe;
  452.     struct pipe_resource *res = This->resource;
  453.     uint8_t *ptr;
  454.     unsigned i;
  455.  
  456.     DBG("This=%p dirty=%i data=%p res=%p\n", This, NineVolume9_IsDirty(This),
  457.         This->data, res);
  458.  
  459.     assert(This->desc.Pool == D3DPOOL_MANAGED);
  460.  
  461.     if (!NineVolume9_IsDirty(This))
  462.         return D3D_OK;
  463.     assert(res);
  464.  
  465.     for (i = 0; i < Elements(This->dirty_box); ++i) {
  466.         const struct pipe_box *box = &This->dirty_box[i];
  467.         if (box->width == 0)
  468.             break;
  469.         ptr = NineVolume9_GetSystemMemPointer(This, box->x, box->y, box->z);
  470.  
  471.         pipe->transfer_inline_write(pipe, res, This->level,
  472.                                     0,
  473.                                     box, ptr, This->stride, This->layer_stride);
  474.     }
  475.     NineVolume9_ClearDirtyRegion(This);
  476.  
  477.     return D3D_OK;
  478. }
  479.  
  480.  
  481. IDirect3DVolume9Vtbl NineVolume9_vtable = {
  482.     (void *)NineUnknown_QueryInterface,
  483.     (void *)NineUnknown_AddRef,
  484.     (void *)NineUnknown_Release,
  485.     (void *)NineUnknown_GetDevice, /* actually part of Volume9 iface */
  486.     (void *)NineVolume9_SetPrivateData,
  487.     (void *)NineVolume9_GetPrivateData,
  488.     (void *)NineVolume9_FreePrivateData,
  489.     (void *)NineVolume9_GetContainer,
  490.     (void *)NineVolume9_GetDesc,
  491.     (void *)NineVolume9_LockBox,
  492.     (void *)NineVolume9_UnlockBox
  493. };
  494.  
  495. static const GUID *NineVolume9_IIDs[] = {
  496.     &IID_IDirect3DVolume9,
  497.     &IID_IUnknown,
  498.     NULL
  499. };
  500.  
  501. HRESULT
  502. NineVolume9_new( struct NineDevice9 *pDevice,
  503.                  struct NineUnknown *pContainer,
  504.                  struct pipe_resource *pResource,
  505.                  unsigned Level,
  506.                  D3DVOLUME_DESC *pDesc,
  507.                  struct NineVolume9 **ppOut )
  508. {
  509.     NINE_DEVICE_CHILD_NEW(Volume9, ppOut, pDevice, /* args */
  510.                           pContainer, pResource, Level, pDesc);
  511. }
  512.  
  513.  
  514. /*** The boring stuff. TODO: Unify with Resource. ***/
  515.  
  516. HRESULT WINAPI
  517. NineVolume9_SetPrivateData( struct NineVolume9 *This,
  518.                             REFGUID refguid,
  519.                             const void *pData,
  520.                             DWORD SizeOfData,
  521.                             DWORD Flags )
  522. {
  523.     enum pipe_error err;
  524.     struct pheader *header;
  525.     const void *user_data = pData;
  526.  
  527.     DBG("This=%p refguid=%p pData=%p SizeOfData=%d Flags=%d\n",
  528.         This, refguid, pData, SizeOfData, Flags);
  529.  
  530.     if (Flags & D3DSPD_IUNKNOWN)
  531.         user_assert(SizeOfData == sizeof(IUnknown *), D3DERR_INVALIDCALL);
  532.  
  533.     /* data consists of a header and the actual data. avoiding 2 mallocs */
  534.     header = CALLOC_VARIANT_LENGTH_STRUCT(pheader, SizeOfData-1);
  535.     if (!header) { return E_OUTOFMEMORY; }
  536.     header->unknown = (Flags & D3DSPD_IUNKNOWN) ? TRUE : FALSE;
  537.  
  538.     /* if the refguid already exists, delete it */
  539.     NineVolume9_FreePrivateData(This, refguid);
  540.  
  541.     /* IUnknown special case */
  542.     if (header->unknown) {
  543.         /* here the pointer doesn't point to the data we want, so point at the
  544.          * pointer making what we eventually copy is the pointer itself */
  545.         user_data = &pData;
  546.     }
  547.  
  548.     header->size = SizeOfData;
  549.     memcpy(header->data, user_data, header->size);
  550.  
  551.     err = util_hash_table_set(This->pdata, refguid, header);
  552.     if (err == PIPE_OK) {
  553.         if (header->unknown) { IUnknown_AddRef(*(IUnknown **)header->data); }
  554.         return D3D_OK;
  555.     }
  556.  
  557.     FREE(header);
  558.     if (err == PIPE_ERROR_OUT_OF_MEMORY) { return E_OUTOFMEMORY; }
  559.  
  560.     return D3DERR_DRIVERINTERNALERROR;
  561. }
  562.  
  563. HRESULT WINAPI
  564. NineVolume9_GetPrivateData( struct NineVolume9 *This,
  565.                             REFGUID refguid,
  566.                             void *pData,
  567.                             DWORD *pSizeOfData )
  568. {
  569.     struct pheader *header;
  570.  
  571.     user_assert(pSizeOfData, E_POINTER);
  572.  
  573.     header = util_hash_table_get(This->pdata, refguid);
  574.     if (!header) { return D3DERR_NOTFOUND; }
  575.  
  576.     if (!pData) {
  577.         *pSizeOfData = header->size;
  578.         return D3D_OK;
  579.     }
  580.     if (*pSizeOfData < header->size) {
  581.         return D3DERR_MOREDATA;
  582.     }
  583.  
  584.     if (header->unknown) { IUnknown_AddRef(*(IUnknown **)header->data); }
  585.     memcpy(pData, header->data, header->size);
  586.  
  587.     return D3D_OK;
  588. }
  589.  
  590. HRESULT WINAPI
  591. NineVolume9_FreePrivateData( struct NineVolume9 *This,
  592.                              REFGUID refguid )
  593. {
  594.     struct pheader *header;
  595.  
  596.     DBG("This=%p refguid=%p\n", This, refguid);
  597.  
  598.     header = util_hash_table_get(This->pdata, refguid);
  599.     if (!header) { return D3DERR_NOTFOUND; }
  600.  
  601.     ht_guid_delete(NULL, header, NULL);
  602.     util_hash_table_remove(This->pdata, refguid);
  603.  
  604.     return D3D_OK;
  605. }
  606.  
  607.