Esempio n. 1
0
void
NineSurface9_SetResourceResize( struct NineSurface9 *This,
                                struct pipe_resource *resource )
{
    assert(This->level == 0 && This->level_actual == 0);
    assert(!This->lock_count);
    assert(This->desc.Pool == D3DPOOL_DEFAULT);
    assert(!This->texture);

    pipe_resource_reference(&This->base.resource, resource);

    This->desc.Width = This->base.info.width0 = resource->width0;
    This->desc.Height = This->base.info.height0 = resource->height0;
    This->desc.MultiSampleType = This->base.info.nr_samples = resource->nr_samples;

    This->stride = nine_format_get_stride(This->base.info.format,
                                          This->desc.Width);

    pipe_surface_reference(&This->surface[0], NULL);
    pipe_surface_reference(&This->surface[1], NULL);
}
Esempio n. 2
0
HRESULT
NineSurface9_ctor( struct NineSurface9 *This,
                   struct NineUnknownParams *pParams,
                   struct NineUnknown *pContainer,
                   struct pipe_resource *pResource,
                   void *user_buffer,
                   uint8_t TextureType,
                   unsigned Level,
                   unsigned Layer,
                   D3DSURFACE_DESC *pDesc )
{
    HRESULT hr;
    union pipe_color_union rgba = {0};
    struct pipe_surface *surf;
    struct pipe_context *pipe = pParams->device->pipe;
    bool allocate = !pContainer && pDesc->Format != D3DFMT_NULL;
    D3DMULTISAMPLE_TYPE multisample_type;

    DBG("This=%p pDevice=%p pResource=%p Level=%u Layer=%u pDesc=%p\n",
        This, pParams->device, pResource, Level, Layer, pDesc);

    /* Mark this as a special surface held by another internal resource. */
    pParams->container = pContainer;
    /* Make sure there's a Desc */
    assert(pDesc);

    /* D3DUSAGE_DYNAMIC isn't allowed on managed buffers */
    user_assert(!(pDesc->Usage & D3DUSAGE_DYNAMIC) ||
                (pDesc->Pool != D3DPOOL_MANAGED), D3DERR_INVALIDCALL);

    assert(allocate || pResource || user_buffer ||
           pDesc->Format == D3DFMT_NULL);
    assert(!allocate || (!pResource && !user_buffer));
    assert(!pResource || !user_buffer);
    assert(!user_buffer || pDesc->Pool != D3DPOOL_DEFAULT);
    assert(!pResource || pDesc->Pool == D3DPOOL_DEFAULT);
    /* Allocation only from create_zs_or_rt_surface with params 0 0 0 */
    assert(!allocate || (Level == 0 && Layer == 0 && TextureType == 0));

    This->data = (uint8_t *)user_buffer;

    multisample_type = pDesc->MultiSampleType;

    /* Map MultiSampleQuality to MultiSampleType */
    hr = d3dmultisample_type_check(pParams->device->screen,
                                   pDesc->Format,
                                   &multisample_type,
                                   pDesc->MultiSampleQuality,
                                   NULL);
    if (FAILED(hr)) {
        return hr;
    }

    /* TODO: this is (except width and height) duplicate from
     * container info (in the pContainer case). Some refactoring is
     * needed to avoid duplication */
    This->base.info.screen = pParams->device->screen;
    This->base.info.target = PIPE_TEXTURE_2D;
    This->base.info.width0 = pDesc->Width;
    This->base.info.height0 = pDesc->Height;
    This->base.info.depth0 = 1;
    This->base.info.last_level = 0;
    This->base.info.array_size = 1;
    This->base.info.nr_samples = multisample_type;
    This->base.info.usage = PIPE_USAGE_DEFAULT;
    This->base.info.bind = PIPE_BIND_SAMPLER_VIEW; /* StretchRect */

    if (pDesc->Usage & D3DUSAGE_RENDERTARGET) {
        This->base.info.bind |= PIPE_BIND_RENDER_TARGET;
    } else if (pDesc->Usage & D3DUSAGE_DEPTHSTENCIL) {
        This->base.info.bind = d3d9_get_pipe_depth_format_bindings(pDesc->Format);
        if (TextureType)
            This->base.info.bind |= PIPE_BIND_SAMPLER_VIEW;
    }

    This->base.info.flags = 0;
    This->base.info.format = d3d9_to_pipe_format_checked(This->base.info.screen,
                                                         pDesc->Format,
                                                         This->base.info.target,
                                                         This->base.info.nr_samples,
                                                         This->base.info.bind,
                                                         FALSE,
                                                         pDesc->Pool == D3DPOOL_SCRATCH);

    if (This->base.info.format == PIPE_FORMAT_NONE && pDesc->Format != D3DFMT_NULL)
        return D3DERR_INVALIDCALL;

    if (allocate && compressed_format(pDesc->Format)) {
        const unsigned w = util_format_get_blockwidth(This->base.info.format);
        const unsigned h = util_format_get_blockheight(This->base.info.format);

        /* Note: In the !allocate case, the test could fail (lower levels of a texture) */
        user_assert(!(pDesc->Width % w) && !(pDesc->Height % h), D3DERR_INVALIDCALL);
    }

    /* Get true format */
    This->format_conversion = d3d9_to_pipe_format_checked(This->base.info.screen,
                                                         pDesc->Format,
                                                         This->base.info.target,
                                                         This->base.info.nr_samples,
                                                         This->base.info.bind,
                                                         FALSE,
                                                         TRUE);
    if (This->base.info.format != This->format_conversion) {
        This->data_conversion = align_calloc(
            nine_format_get_level_alloc_size(This->format_conversion,
                                             pDesc->Width,
                                             pDesc->Height,
                                             0), 32);
        if (!This->data_conversion)
            return E_OUTOFMEMORY;
        This->stride_conversion = nine_format_get_stride(This->format_conversion,
                                                         pDesc->Width);
    }

    if ((allocate && pDesc->Pool != D3DPOOL_DEFAULT) || pDesc->Format == D3DFMT_NULL) {
        /* Ram buffer with no parent. Has to allocate the resource itself */
        assert(!user_buffer);
        This->data = align_calloc(
            nine_format_get_level_alloc_size(This->base.info.format,
                                             pDesc->Width,
                                             pDesc->Height,
                                             0), 32);
        if (!This->data)
            return E_OUTOFMEMORY;
    }

    hr = NineResource9_ctor(&This->base, pParams, pResource,
                            allocate && (pDesc->Pool == D3DPOOL_DEFAULT),
                            D3DRTYPE_SURFACE, pDesc->Pool, pDesc->Usage);

    if (FAILED(hr))
        return hr;

    This->pipe = This->base.base.device->pipe;
    This->transfer = NULL;

    This->texture = TextureType;
    This->level = Level;
    This->level_actual = Level;
    This->layer = Layer;
    This->desc = *pDesc;

    This->stride = nine_format_get_stride(This->base.info.format, pDesc->Width);

    if (This->base.resource && (pDesc->Usage & D3DUSAGE_DYNAMIC))
        This->base.resource->flags |= NINE_RESOURCE_FLAG_LOCKABLE;

    /* TODO: investigate what else exactly needs to be cleared */
    if (This->base.resource && (pDesc->Usage & D3DUSAGE_RENDERTARGET)) {
        surf = NineSurface9_GetSurface(This, 0);
        pipe->clear_render_target(pipe, surf, &rgba, 0, 0, pDesc->Width, pDesc->Height, false);
    }

    NineSurface9_Dump(This);

    return D3D_OK;
}
Esempio n. 3
0
HRESULT
NineSurface9_ctor( struct NineSurface9 *This,
                   struct NineUnknownParams *pParams,
                   struct NineUnknown *pContainer,
                   struct pipe_resource *pResource,
                   void *user_buffer,
                   uint8_t TextureType,
                   unsigned Level,
                   unsigned Layer,
                   D3DSURFACE_DESC *pDesc )
{
    HRESULT hr;

    DBG("This=%p pDevice=%p pResource=%p Level=%u Layer=%u pDesc=%p\n",
        This, pParams->device, pResource, Level, Layer, pDesc);

    /* Mark this as a special surface held by another internal resource. */
    pParams->container = pContainer;

    user_assert(!(pDesc->Usage & D3DUSAGE_DYNAMIC) ||
                (pDesc->Pool != D3DPOOL_MANAGED), D3DERR_INVALIDCALL);

    assert(pResource || (user_buffer && pDesc->Pool != D3DPOOL_DEFAULT) ||
           (!pContainer && pDesc->Pool != D3DPOOL_DEFAULT) ||
           pDesc->Format == D3DFMT_NULL);

    assert(!pResource || !user_buffer);
    assert(!user_buffer || pDesc->Pool != D3DPOOL_DEFAULT);
    /* The only way we can have !pContainer is being created
     * from create_zs_or_rt_surface with params 0 0 0 */
    assert(pContainer || (Level == 0 && Layer == 0 && TextureType == 0));

    This->data = (uint8_t *)user_buffer;

    This->base.info.screen = pParams->device->screen;
    This->base.info.target = PIPE_TEXTURE_2D;
    This->base.info.width0 = pDesc->Width;
    This->base.info.height0 = pDesc->Height;
    This->base.info.depth0 = 1;
    This->base.info.last_level = 0;
    This->base.info.array_size = 1;
    This->base.info.nr_samples = pDesc->MultiSampleType;
    This->base.info.usage = PIPE_USAGE_DEFAULT;
    This->base.info.bind = PIPE_BIND_SAMPLER_VIEW;
    This->base.info.flags = 0;
    This->base.info.format = d3d9_to_pipe_format_checked(This->base.info.screen,
                                                         pDesc->Format,
                                                         This->base.info.target,
                                                         This->base.info.nr_samples,
                                                         This->base.info.bind,
                                                         FALSE);

    if (pDesc->Usage & D3DUSAGE_RENDERTARGET)
        This->base.info.bind |= PIPE_BIND_RENDER_TARGET;
    if (pDesc->Usage & D3DUSAGE_DEPTHSTENCIL)
        This->base.info.bind |= PIPE_BIND_DEPTH_STENCIL;

    /* Ram buffer with no parent. Has to allocate the resource itself */
    if (!pResource && !pContainer) {
        assert(!user_buffer);
        This->data = MALLOC(
            nine_format_get_level_alloc_size(This->base.info.format,
                                             pDesc->Width,
                                             pDesc->Height,
                                             0));
        if (!This->data)
            return E_OUTOFMEMORY;
    }

    if (pDesc->Pool == D3DPOOL_SYSTEMMEM) {
        This->base.info.usage = PIPE_USAGE_STAGING;
        assert(!pResource);
    } else {
        if (pResource && (pDesc->Usage & D3DUSAGE_DYNAMIC))
            pResource->flags |= NINE_RESOURCE_FLAG_LOCKABLE;
    }

    hr = NineResource9_ctor(&This->base, pParams, pResource, FALSE, D3DRTYPE_SURFACE,
                            pDesc->Pool, pDesc->Usage);
    if (FAILED(hr))
        return hr;

    This->pipe = This->base.base.device->pipe;
    This->transfer = NULL;

    This->texture = TextureType;
    This->level = Level;
    This->level_actual = Level;
    This->layer = Layer;
    This->desc = *pDesc;

    This->stride = nine_format_get_stride(This->base.info.format, pDesc->Width);

    if (pResource && NineSurface9_IsOffscreenPlain(This))
        pResource->flags |= NINE_RESOURCE_FLAG_LOCKABLE;

    NineSurface9_Dump(This);

    return D3D_OK;
}
Esempio n. 4
0
static HRESULT
NineVolume9_ctor( struct NineVolume9 *This,
                  struct NineUnknownParams *pParams,
                  struct NineUnknown *pContainer,
                  struct pipe_resource *pResource,
                  unsigned Level,
                  D3DVOLUME_DESC *pDesc )
{
    HRESULT hr;

    assert(pContainer); /* stand-alone volumes can't be created */

    DBG("This=%p pContainer=%p pDevice=%p pResource=%p Level=%u pDesc=%p\n",
        This, pContainer, pParams->device, pResource, Level, pDesc);

    /* Mark this as a special surface held by another internal resource. */
    pParams->container = pContainer;

    user_assert(!(pDesc->Usage & D3DUSAGE_DYNAMIC) ||
                (pDesc->Pool != D3DPOOL_MANAGED), D3DERR_INVALIDCALL);

    assert(pResource || pDesc->Pool != D3DPOOL_DEFAULT);

    hr = NineUnknown_ctor(&This->base, pParams);
    if (FAILED(hr))
        return hr;

    pipe_resource_reference(&This->resource, pResource);

    This->pipe = pParams->device->pipe;
    This->transfer = NULL;
    This->lock_count = 0;

    This->level = Level;
    This->level_actual = Level;
    This->desc = *pDesc;

    This->info.screen = pParams->device->screen;
    This->info.target = PIPE_TEXTURE_3D;
    This->info.width0 = pDesc->Width;
    This->info.height0 = pDesc->Height;
    This->info.depth0 = pDesc->Depth;
    This->info.last_level = 0;
    This->info.array_size = 1;
    This->info.nr_samples = 0;
    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);

    /* 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_malloc(This->layer_stride_conversion *
                                             This->desc.Depth, 32);
        if (!This->data_conversion)
            return E_OUTOFMEMORY;
    }

    if (!This->resource) {
        hr = NineVolume9_AllocateData(This);
        if (FAILED(hr))
            return hr;
    }
    return D3D_OK;
}