Exemplo n.º 1
0
void
NineSurface9_Dump( struct NineSurface9 *This )
{
    struct NineBaseTexture9 *tex;
    GUID id = IID_IDirect3DBaseTexture9;
    REFIID ref = &id;

    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->data,
        nine_D3DPOOL_to_str(This->desc.Pool),
        nine_D3DRTYPE_to_str(This->desc.Type),
        nine_D3DUSAGE_to_str(This->desc.Usage),
        This->desc.Width, This->desc.Height,
        d3dformat_to_string(This->desc.Format), This->stride,
        This->base.resource &&
        (This->base.resource->flags & NINE_RESOURCE_FLAG_LOCKABLE),
        This->level, This->level_actual, This->layer);

    if (!This->base.base.container)
        return;
    NineUnknown_QueryInterface(This->base.base.container, ref, (void **)&tex);
    if (tex) {
        NineBaseTexture9_Dump(tex);
        NineUnknown_Release(NineUnknown(tex));
    }
}
Exemplo n.º 2
0
HRESULT
NineBaseTexture9_UpdateSamplerView( struct NineBaseTexture9 *This,
                                    const int sRGB )
{
    const struct util_format_description *desc;
    struct pipe_context *pipe;
    struct pipe_screen *screen = NineDevice9_GetScreen(This->base.base.device);
    struct pipe_resource *resource = This->base.resource;
    struct pipe_sampler_view templ;
    enum pipe_format srgb_format;
    unsigned i;
    uint8_t swizzle[4];

    DBG("This=%p sRGB=%d\n", This, sRGB);

    if (unlikely(!resource)) {
	if (unlikely(This->format == D3DFMT_NULL))
            return D3D_OK;
        NineBaseTexture9_Dump(This);
    }
    assert(resource);

    pipe_sampler_view_reference(&This->view[sRGB], NULL);

    swizzle[0] = PIPE_SWIZZLE_X;
    swizzle[1] = PIPE_SWIZZLE_Y;
    swizzle[2] = PIPE_SWIZZLE_Z;
    swizzle[3] = PIPE_SWIZZLE_W;
    desc = util_format_description(resource->format);
    if (desc->colorspace == UTIL_FORMAT_COLORSPACE_ZS) {
        /* msdn doc is incomplete here and wrong.
         * The only formats that can be read directly here
         * are DF16, DF24 and INTZ.
         * Tested on win the swizzle is
         * R = depth, G = B = 0, A = 1 for DF16 and DF24
         * R = G = B = A = depth for INTZ
         * For the other ZS formats that can't be read directly
         * but can be used as shadow map, the result is duplicated on
         * all channel */
        if (This->format == D3DFMT_DF16 ||
            This->format == D3DFMT_DF24) {
            swizzle[1] = PIPE_SWIZZLE_0;
            swizzle[2] = PIPE_SWIZZLE_0;
            swizzle[3] = PIPE_SWIZZLE_1;
        } else {
            swizzle[1] = PIPE_SWIZZLE_X;
            swizzle[2] = PIPE_SWIZZLE_X;
            swizzle[3] = PIPE_SWIZZLE_X;
        }
    } else if (resource->format == PIPE_FORMAT_RGTC2_UNORM) {
        swizzle[0] = PIPE_SWIZZLE_Y;
        swizzle[1] = PIPE_SWIZZLE_X;
        swizzle[2] = PIPE_SWIZZLE_1;
        swizzle[3] = PIPE_SWIZZLE_1;
    } else if (resource->format != PIPE_FORMAT_A8_UNORM &&
               resource->format != PIPE_FORMAT_RGTC1_UNORM) {
        /* exceptions:
         * A8 should have 0.0 as default values for RGB.
         * ATI1/RGTC1 should be r 0 0 1 (tested on windows).
         * It is already what gallium does. All the other ones
         * should have 1.0 for non-defined values */
        for (i = 0; i < 4; i++) {
            if (SWIZZLE_TO_REPLACE(desc->swizzle[i]))
                swizzle[i] = PIPE_SWIZZLE_1;
        }
    }

    /* if requested and supported, convert to the sRGB format */
    srgb_format = util_format_srgb(resource->format);
    if (sRGB && srgb_format != PIPE_FORMAT_NONE &&
        screen->is_format_supported(screen, srgb_format,
                                    resource->target, 0, 0, resource->bind))
        templ.format = srgb_format;
    else
        templ.format = resource->format;
    templ.u.tex.first_layer = 0;
    templ.u.tex.last_layer = resource->target == PIPE_TEXTURE_3D ?
                             resource->depth0 - 1 : resource->array_size - 1;
    templ.u.tex.first_level = 0;
    templ.u.tex.last_level = resource->last_level;
    templ.swizzle_r = swizzle[0];
    templ.swizzle_g = swizzle[1];
    templ.swizzle_b = swizzle[2];
    templ.swizzle_a = swizzle[3];
    templ.target = resource->target;

    pipe = nine_context_get_pipe_acquire(This->base.base.device);
    This->view[sRGB] = pipe->create_sampler_view(pipe, resource, &templ);
    nine_context_get_pipe_release(This->base.base.device);

    DBG("sampler view = %p(resource = %p)\n", This->view[sRGB], resource);

    return This->view ? D3D_OK : D3DERR_DRIVERINTERNALERROR;
}