void
NineBaseTexture9_Dump( struct NineBaseTexture9 *This )
{
- DBG("\nNineBaseTexture9(%p->%p/%p): Pool=%s Type=%s Usage=%s\n"
+ DBG("\nNineBaseTexture9(%p->NULL/%p): Pool=%s Type=%s Usage=%s\n"
"Format=%s Dims=%ux%ux%u/%u LastLevel=%u Lod=%u(%u)\n", This,
- This->base.resource, This->base.data,
+ This->base.resource,
nine_D3DPOOL_to_str(This->base.pool),
nine_D3DRTYPE_to_str(This->base.type),
nine_D3DUSAGE_to_str(This->base.usage),
sfdesc.Width = sfdesc.Height = u_minify(EdgeLength, i / 6);
hr = NineSurface9_new(This->base.base.base.device, NineUnknown(This),
- This->base.base.resource, D3DRTYPE_CUBETEXTURE,
+ This->base.base.resource, NULL, D3DRTYPE_CUBETEXTURE,
i / 6, i % 6,
&sfdesc, &This->surfaces[i]);
if (FAILED(hr))
return D3DERR_OUTOFVIDEOMEMORY;
}
- This->data = NULL; /* FIXME remove, rather set it to null in surface9.c*/
This->type = Type;
This->pool = Pool;
This->usage = Usage;
* still hold a reference. */
pipe_resource_reference(&This->resource, NULL);
- /* release allocated system memory for non-D3DPOOL_DEFAULT resources */
- if (This->data)
- FREE(This->data);
-
NineUnknown_dtor(&This->base);
}
struct pipe_resource *resource; /* device resource */
- uint8_t *data; /* system memory backing */
-
D3DRESOURCETYPE type;
D3DPOOL pool;
DWORD priority;
struct NineUnknownParams *pParams,
struct NineUnknown *pContainer,
struct pipe_resource *pResource,
+ void *user_buffer,
uint8_t TextureType,
unsigned Level,
unsigned Layer,
assert(pResource ||
pDesc->Pool != D3DPOOL_DEFAULT || pDesc->Format == D3DFMT_NULL);
+ assert(!pResource || !user_buffer);
+
This->base.info.screen = pParams->device->screen;
This->base.info.target = PIPE_TEXTURE_2D;
This->base.info.format = d3d9_to_pipe_format(pDesc->Format);
if (pDesc->Pool == D3DPOOL_SYSTEMMEM) {
This->base.info.usage = PIPE_USAGE_STAGING;
- if (pResource)
- This->base.data = (uint8_t *)pResource; /* this is *pSharedHandle */
- pResource = NULL;
+ This->data = (uint8_t *)user_buffer; /* this is *pSharedHandle */
+ assert(!pResource);
} else {
if (pResource && (pDesc->Usage & D3DUSAGE_DYNAMIC))
pResource->flags |= NINE_RESOURCE_FLAG_LOCKABLE;
This->stride = util_format_get_stride(This->base.info.format, pDesc->Width);
This->stride = align(This->stride, 4);
- if (!pResource && !This->base.data) {
- hr = NineSurface9_AllocateData(This);
- if (FAILED(hr))
- return hr;
+ if (!pResource && !This->data) {
+ const unsigned size = This->stride *
+ util_format_get_nblocksy(This->base.info.format, This->desc.Height);
+
+ DBG("(%p(This=%p),level=%u) Allocating 0x%x bytes of system memory.\n",
+ This->base.base.container, This, This->level, size);
+
+ This->data = (uint8_t *)MALLOC(size);
+ if (!This->data)
+ return E_OUTOFMEMORY;
+ This->manage_data = TRUE;
} else {
if (pResource && NineSurface9_IsOffscreenPlain(This))
- pResource->flags |= NINE_RESOURCE_FLAG_LOCKABLE;
+ pResource->flags |= NINE_RESOURCE_FLAG_LOCKABLE; /* why setting this flag there ? too late ? should be before NineResource9_ctor call perhaps ? */
}
NineSurface9_Dump(This);
pipe_surface_reference(&This->surface[0], NULL);
pipe_surface_reference(&This->surface[1], NULL);
+ /* release allocated system memory for non-D3DPOOL_DEFAULT resources */
+ if (This->manage_data && This->data)
+ FREE(This->data);
NineResource9_dtor(&This->base);
}
DBG("\nNineSurface9(%p->%p/%p): Pool=%s Type=%s Usage=%s\n"
"Dims=%ux%u Format=%s Stride=%u Lockable=%i\n"
- "Level=%u(%u), Layer=%u\n", This, This->base.resource, This->base.data,
+ "Level=%u(%u), Layer=%u\n", This, This->base.resource, This->data,
nine_D3DPOOL_to_str(This->desc.Pool),
nine_D3DRTYPE_to_str(This->desc.Type),
nine_D3DUSAGE_to_str(This->desc.Usage),
y = util_format_get_nblocksy(This->base.info.format, y);
- assert(This->base.data);
- return This->base.data + (y * This->stride + x_offset);
+ assert(This->data);
+ return This->data + (y * This->stride + x_offset);
}
HRESULT WINAPI
user_warn(This->desc.Format == D3DFMT_NULL);
- if (This->base.data) {
+ if (This->data) {
DBG("returning system memory\n");
pLockedRect->Pitch = This->stride;
STUB(D3DERR_INVALIDCALL);
}
-/* nine private */
-
-HRESULT
-NineSurface9_AllocateData( struct NineSurface9 *This )
-{
-#if 0
- struct pipe_screen *screen = This->base.info.screen;
- /* XXX: Can't use staging resource because apparently apps expect
- * memory offsets to be the same across locks.
- * NV50 doesn't support direct mapping yet so only enable this if
- * everything else works.
- */
- if (This->base.pool == D3DPOOL_SYSTEMMEM) {
- /* Allocate a staging resource to save a copy:
- * user -> staging resource
- * staging resource -> (blit) -> video memory
- *
- * Instead of:
- * user -> system memory
- * system memory -> transfer staging area
- * transfer -> video memory
- *
- * Does this work if we "lose" the device ?
- */
- struct pipe_resource *resource;
- struct pipe_resource templ;
-
- templ.target = PIPE_TEXTURE_2D;
- templ.format = This->base.info.format;
- templ.width0 = This->desc.Width;
- templ.height0 = This->desc.Height;
- templ.depth0 = 1;
- templ.array_size = 1;
- templ.last_level = 0;
- templ.nr_samples = 0;
- templ.usage = PIPE_USAGE_STAGING;
- templ.bind =
- PIPE_BIND_SAMPLER_VIEW |
- PIPE_BIND_TRANSFER_WRITE |
- PIPE_BIND_TRANSFER_READ;
- templ.flags = 0;
-
- DBG("(%p(This=%p),level=%u) Allocating staging resource.\n",
- This->base.base.container, This, This->level);
-
- resource = screen->resource_create(screen, &templ);
- if (!resource)
- DBG("Failed to allocate staging resource.\n");
-
- /* Also deallocate old staging resource. */
- pipe_resource_reference(&This->base.resource, resource);
- }
-#endif
- if (!This->base.resource) {
- const unsigned size = This->stride *
- util_format_get_nblocksy(This->base.info.format, This->desc.Height);
-
- DBG("(%p(This=%p),level=%u) Allocating 0x%x bytes of system memory.\n",
- This->base.base.container, This, This->level, size);
-
- This->base.data = (uint8_t *)MALLOC(size);
- if (!This->base.data)
- return E_OUTOFMEMORY;
- }
- return D3D_OK;
-}
-
IDirect3DSurface9Vtbl NineSurface9_vtable = {
(void *)NineUnknown_QueryInterface,
(void *)NineUnknown_AddRef,
NineSurface9_new( struct NineDevice9 *pDevice,
struct NineUnknown *pContainer,
struct pipe_resource *pResource,
+ void *user_buffer,
uint8_t TextureType,
unsigned Level,
unsigned Layer,
struct NineSurface9 **ppOut )
{
NINE_DEVICE_CHILD_NEW(Surface9, ppOut, pDevice, /* args */
- pContainer, pResource,
+ pContainer, pResource, user_buffer,
TextureType, Level, Layer, pDesc);
}
unsigned layer;
D3DSURFACE_DESC desc;
+ uint8_t *data; /* system memory backing */
+ boolean manage_data;
unsigned stride; /* for system memory backing */
/* wine doesn't even use these, 2 will be enough */
NineSurface9_new( struct NineDevice9 *pDevice,
struct NineUnknown *pContainer,
struct pipe_resource *pResource,
+ void *user_buffer,
uint8_t TextureType, /* 0 if pContainer isn't BaseTexure9 */
unsigned Level,
unsigned Layer,
struct NineUnknownParams *pParams,
struct NineUnknown *pContainer,
struct pipe_resource *pResource,
+ void *user_buffer,
uint8_t TextureType,
unsigned Level,
unsigned Layer,
memset(&This->dirty_rects, 0, sizeof(This->dirty_rects));
}
-HRESULT
-NineSurface9_AllocateData( struct NineSurface9 *This );
-
HRESULT
NineSurface9_UploadSelf( struct NineSurface9 *This );
} else {
desc.Format = pParams->BackBufferFormat;
desc.Usage = D3DUSAGE_RENDERTARGET;
- hr = NineSurface9_new(pDevice, NineUnknown(This), resource, 0,
+ hr = NineSurface9_new(pDevice, NineUnknown(This), resource, NULL, 0,
0, 0, &desc, &This->buffers[i]);
if (has_present_buffers)
pipe_resource_reference(&resource, NULL);
/* XXX wine thinks the container of this should be the device */
desc.Format = pParams->AutoDepthStencilFormat;
desc.Usage = D3DUSAGE_DEPTHSTENCIL;
- hr = NineSurface9_new(pDevice, NineUnknown(pDevice), resource, 0,
+ hr = NineSurface9_new(pDevice, NineUnknown(pDevice), resource, NULL, 0,
0, 0, &desc, &This->zsbuf);
pipe_resource_reference(&resource, NULL);
if (FAILED(hr)) {
/* NineSurface9_CopySurface needs same format. */
desc.Format = dest_surface->desc.Format;
desc.Usage = D3DUSAGE_RENDERTARGET;
- hr = NineSurface9_new(pDevice, NineUnknown(This), temp_resource, 0,
+ hr = NineSurface9_new(pDevice, NineUnknown(This), temp_resource, NULL, 0,
0, 0, &desc, &temp_surface);
pipe_resource_reference(&temp_resource, NULL);
if (FAILED(hr)) {
{
struct pipe_screen *screen = pParams->device->screen;
struct pipe_resource *info = &This->base.base.info;
+ struct pipe_resource *resource;
unsigned l;
D3DSURFACE_DESC sfdesc;
HRESULT hr;
- const boolean shared_create = pSharedHandle && !*pSharedHandle;
+ void *user_buffer = NULL;
DBG("(%p) Width=%u Height=%u Levels=%u Usage=%s Format=%s Pool=%s "
"pSharedHandle=%p\n", This, Width, Height, Levels,
Pool == D3DPOOL_DEFAULT, D3DERR_INVALIDCALL);
if (pSharedHandle && Pool == D3DPOOL_DEFAULT) {
- /* Note: Below there is some implementation to support buffer sharing in
- * this case, but it won't work for cross-process. Thus just ignore
- * that code. */
- if (shared_create) {
+ if (!*pSharedHandle) {
DBG("Creating Texture with invalid handle. Importing will fail\n.");
*pSharedHandle = (HANDLE)1; /* Wine would keep it NULL */
pSharedHandle = NULL;
if (Pool == D3DPOOL_SYSTEMMEM)
info->usage = PIPE_USAGE_STAGING;
- if (pSharedHandle && !shared_create) {
- if (Pool == D3DPOOL_SYSTEMMEM) {
- /* Hack for surface creation. */
- This->base.base.resource = (struct pipe_resource *)*pSharedHandle;
- } else {
- struct pipe_resource *res;
- res = screen->resource_from_handle(screen, info,
- (struct winsys_handle *)pSharedHandle);
- if (!res)
- return D3DERR_NOTFOUND;
- This->base.base.resource = res;
- }
+ if (pSharedHandle && *pSharedHandle) { /* Pool == D3DPOOL_SYSTEMMEM */
+ user_buffer = (void *)*pSharedHandle;
}
This->surfaces = CALLOC(info->last_level + 1, sizeof(*This->surfaces));
sfdesc.Pool = Pool;
sfdesc.MultiSampleType = D3DMULTISAMPLE_NONE;
sfdesc.MultiSampleQuality = 0;
+
+ if (Pool == D3DPOOL_SYSTEMMEM)
+ resource = NULL;
+ else
+ resource = This->base.base.resource;
+
for (l = 0; l <= info->last_level; ++l) {
sfdesc.Width = u_minify(Width, l);
sfdesc.Height = u_minify(Height, l);
hr = NineSurface9_new(This->base.base.base.device, NineUnknown(This),
- This->base.base.resource, D3DRTYPE_TEXTURE, l, 0,
+ resource, user_buffer,
+ D3DRTYPE_TEXTURE, l, 0,
&sfdesc, &This->surfaces[l]);
if (FAILED(hr))
return hr;
This->dirty_rect.depth = 1; /* widht == 0 means empty, depth stays 1 */
- if (pSharedHandle) {
- if (Pool == D3DPOOL_SYSTEMMEM) {
- This->base.base.resource = NULL;
- if (shared_create)
- *pSharedHandle = This->surfaces[0]->base.data;
- } else
- if (shared_create) {
- boolean ok;
- ok = screen->resource_get_handle(screen, This->base.base.resource,
- (struct winsys_handle *)pSharedHandle);
- if (!ok)
- return D3DERR_DRIVERINTERNALERROR;
- }
+ if (pSharedHandle && !*pSharedHandle) {/* Pool == D3DPOOL_SYSTEMMEM */
+ *pSharedHandle = This->surfaces[0]->data;
}
return D3D_OK;