Beispiel #1
0
HRESULT
NineSwapChain9_ctor( struct NineSwapChain9 *This,
                     struct NineUnknownParams *pParams,
                     BOOL implicit,
                     ID3DPresent *pPresent,
                     struct d3dadapter9_context *pCTX,
                     HWND hFocusWindow )
{
    D3DPRESENT_PARAMETERS params;
    HRESULT hr;

    DBG("This=%p pDevice=%p pPresent=%p pCTX=%p hFocusWindow=%p\n",
        This, pParams->device, pPresent, pCTX, hFocusWindow);

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

    This->screen = NineDevice9_GetScreen(This->base.device);
    This->pipe = NineDevice9_GetPipe(This->base.device);
    This->cso = NineDevice9_GetCSO(This->base.device);
    This->implicit = implicit;
    This->actx = pCTX;
    This->present = pPresent;
    ID3DPresent_AddRef(pPresent);
    hr = ID3DPresent_GetPresentParameters(This->present, &params);
    if (FAILED(hr))
        return hr;
    if (!params.hDeviceWindow)
        params.hDeviceWindow = hFocusWindow;

    return NineSwapChain9_Resize(This, &params);
}
Beispiel #2
0
HRESULT
NineResource9_ctor( struct NineResource9 *This,
                    struct NineUnknownParams *pParams,
                    BOOL Allocate,
                    D3DRESOURCETYPE Type,
                    D3DPOOL Pool )
{
    struct pipe_screen *screen;
    HRESULT hr;

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

    This->info.screen = screen = This->base.device->screen;

    if (Allocate) {
        DBG("(%p) Creating pipe_resource.\n", This);
        This->resource = screen->resource_create(screen, &This->info);
        if (!This->resource)
            return D3DERR_OUTOFVIDEOMEMORY;
    }

    This->data = NULL; /* FIXME remove, rather set it to null in surface9.c*/
    This->type = Type;
    This->pool = Pool;
    This->priority = 0;

    This->pdata = util_hash_table_create(ht_guid_hash, ht_guid_compare);
    if (!This->pdata)
        return E_OUTOFMEMORY;

    return D3D_OK;
}
Beispiel #3
0
HRESULT
NinePixelShader9_ctor( struct NinePixelShader9 *This,
                       struct NineUnknownParams *pParams,
                       const DWORD *pFunction, void *cso )
{
    struct NineDevice9 *device;
    struct nine_shader_info info;
    struct pipe_context *pipe;
    HRESULT hr;

    DBG("This=%p pParams=%p pFunction=%p cso=%p\n", This, pParams, pFunction, cso);

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

    if (cso) {
        This->ff_cso = cso;
        return D3D_OK;
    }
    device = This->base.device;

    info.type = PIPE_SHADER_FRAGMENT;
    info.byte_code = pFunction;
    info.const_i_base = NINE_CONST_I_BASE(device->max_ps_const_f) / 16;
    info.const_b_base = NINE_CONST_B_BASE(device->max_ps_const_f) / 16;
    info.sampler_mask_shadow = 0x0;
    info.sampler_ps1xtypes = 0x0;
    info.fog_enable = 0;
    info.projected = 0;
    info.process_vertices = false;

    pipe = nine_context_get_pipe_acquire(device);
    hr = nine_translate_shader(device, &info, pipe);
    nine_context_get_pipe_release(device);
    if (FAILED(hr))
        return hr;
    This->byte_code.version = info.version;

    This->byte_code.tokens = mem_dup(pFunction, info.byte_size);
    if (!This->byte_code.tokens)
        return E_OUTOFMEMORY;
    This->byte_code.size = info.byte_size;

    This->variant.cso = info.cso;
    This->last_cso = info.cso;
    This->last_key = 0;

    This->sampler_mask = info.sampler_mask;
    This->rt_mask = info.rt_mask;
    This->const_used_size = info.const_used_size;
    This->bumpenvmat_needed = info.bumpenvmat_needed;
    /* no constant relative addressing for ps */
    assert(info.lconstf.data == NULL);
    assert(info.lconstf.ranges == NULL);

    return D3D_OK;
}
Beispiel #4
0
HRESULT
NinePixelShader9_ctor( struct NinePixelShader9 *This,
                       struct NineUnknownParams *pParams,
                       const DWORD *pFunction, void *cso )
{
    struct NineDevice9 *device;
    struct nine_shader_info info;
    HRESULT hr;

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

    if (cso) {
        This->variant.cso = cso;
        return D3D_OK;
    }
    device = This->base.device;

    info.type = PIPE_SHADER_FRAGMENT;
    info.byte_code = pFunction;
    info.const_i_base = NINE_CONST_I_BASE(device->max_ps_const_f) / 16;
    info.const_b_base = NINE_CONST_B_BASE(device->max_ps_const_f) / 16;
    info.sampler_mask_shadow = 0x0;
    info.sampler_ps1xtypes = 0x0;

    hr = nine_translate_shader(device, &info);
    if (FAILED(hr))
        return hr;
    This->byte_code.version = info.version;

    This->byte_code.tokens = mem_dup(pFunction, info.byte_size);
    if (!This->byte_code.tokens)
        return E_OUTOFMEMORY;
    This->byte_code.size = info.byte_size;

    This->variant.cso = info.cso;
    This->sampler_mask = info.sampler_mask;
    This->rt_mask = info.rt_mask;
    This->const_used_size = info.const_used_size;
    if (info.const_used_size == ~0)
        This->const_used_size = NINE_CONSTBUF_SIZE(device->max_ps_const_f);
    This->lconstf = info.lconstf;

    return D3D_OK;
}
Beispiel #5
0
HRESULT
NineStateBlock9_ctor( struct NineStateBlock9 *This,
                      struct NineUnknownParams *pParams,
                      enum nine_stateblock_type type )
{
    HRESULT hr = NineUnknown_ctor(&This->base, pParams);
    if (FAILED(hr))
        return hr;

    This->type = type;

    This->state.vs_const_f = MALLOC(pParams->device->constbuf_vs->width0);
    This->state.ps_const_f = MALLOC(pParams->device->constbuf_ps->width0);
    if (!This->state.vs_const_f || !This->state.ps_const_f)
        return E_OUTOFMEMORY;

    return D3D_OK;
}
Beispiel #6
0
HRESULT
NineSwapChain9_ctor( struct NineSwapChain9 *This,
                     struct NineUnknownParams *pParams,
                     BOOL implicit,
                     ID3DPresent *pPresent,
                     D3DPRESENT_PARAMETERS *pPresentationParameters,
                     struct d3dadapter9_context *pCTX,
                     HWND hFocusWindow,
                     D3DDISPLAYMODEEX *mode )
{
    HRESULT hr;

    DBG("This=%p pDevice=%p pPresent=%p pCTX=%p hFocusWindow=%p\n",
        This, pParams->device, pPresent, pCTX, hFocusWindow);

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

    This->screen = NineDevice9_GetScreen(This->base.device);
    This->implicit = implicit;
    This->actx = pCTX;
    This->present = pPresent;
    This->mode = NULL;

    ID3DPresent_AddRef(pPresent);
    if (!This->actx->thread_submit &&
        This->base.device->minor_version_num > 2) {
        D3DPRESENT_PARAMETERS2 params2;

        memset(&params2, 0, sizeof(D3DPRESENT_PARAMETERS2));
        params2.AllowDISCARDDelayedRelease = This->actx->discard_delayed_release;
        params2.TearFreeDISCARD = This->actx->tearfree_discard;
        ID3DPresent_SetPresentParameters2(pPresent, &params2);
    }

    if (!pPresentationParameters->hDeviceWindow)
        pPresentationParameters->hDeviceWindow = hFocusWindow;

    This->rendering_done = FALSE;
    This->pool = NULL;
    return NineSwapChain9_Resize(This, pPresentationParameters, mode);
}
HRESULT
NineStateBlock9_ctor( struct NineStateBlock9 *This,
                      struct NineUnknownParams *pParams,
                      enum nine_stateblock_type type )
{
    HRESULT hr = NineUnknown_ctor(&This->base, pParams);

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

    if (FAILED(hr))
        return hr;

    This->type = type;

    This->state.vs_const_f = MALLOC(This->base.device->vs_const_size);
    This->state.ps_const_f = MALLOC(This->base.device->ps_const_size);
    if (!This->state.vs_const_f || !This->state.ps_const_f)
        return E_OUTOFMEMORY;

    return D3D_OK;
}
Beispiel #8
0
HRESULT
NineQuery9_ctor( struct NineQuery9 *This,
                 struct NineUnknownParams *pParams,
                 D3DQUERYTYPE Type )
{
    struct pipe_context *pipe = pParams->device->pipe;
    const unsigned ptype = d3dquerytype_to_pipe_query(pParams->device->screen, Type);
    HRESULT hr;

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

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

    This->state = NINE_QUERY_STATE_FRESH;
    This->type = Type;

    user_assert(ptype != ~0, D3DERR_INVALIDCALL);

    if (ptype < PIPE_QUERY_TYPES) {
        This->pq = pipe->create_query(pipe, ptype, 0);
        if (!This->pq)
            return E_OUTOFMEMORY;
    } else {
        assert(0); /* we have checked this case before */
    }

    This->instant =
        Type == D3DQUERYTYPE_EVENT ||
        Type == D3DQUERYTYPE_RESOURCEMANAGER ||
        Type == D3DQUERYTYPE_TIMESTAMP ||
        Type == D3DQUERYTYPE_TIMESTAMPFREQ ||
        Type == D3DQUERYTYPE_VCACHE ||
        Type == D3DQUERYTYPE_VERTEXSTATS;

    This->result_size = nine_query_result_size(Type);

    return D3D_OK;
}
Beispiel #9
0
HRESULT
NineAdapter9_ctor( struct NineAdapter9 *This,
                   struct NineUnknownParams *pParams,
                   struct d3dadapter9_context *pCTX )
{
    struct pipe_screen *hal = pCTX->hal;
    HRESULT hr = NineUnknown_ctor(&This->base, pParams);
    if (FAILED(hr)) { return hr; }

    DBG("This=%p pParams=%p pCTX=%p\n", This, pParams, pCTX);
    nine_dump_D3DADAPTER_IDENTIFIER9(DBG_CHANNEL, &pCTX->identifier);

    This->ctx = pCTX;
    if (!hal->get_param(hal, PIPE_CAP_CLIP_HALFZ)) {
        ERR("Driver doesn't support d3d9 coordinates\n");
        return D3DERR_DRIVERINTERNALERROR;
    }
    if (This->ctx->ref &&
        !This->ctx->ref->get_param(This->ctx->ref, PIPE_CAP_CLIP_HALFZ)) {
        ERR("Warning: Sotware rendering driver doesn't support d3d9 coordinates\n");
    }
    /* Old cards had tricks to bypass some restrictions to implement
     * everything and fit tight the requirements: number of constants,
     * number of temp registers, special behaviours, etc. Since we don't
     * have access to all this, we need a bit more than what dx9 required.
     * For example we have to use more than 32 temp registers to emulate
     * behaviours, while some dx9 hw don't have more. As for sm2 hardware,
     * we could support vs2 / ps2 for them but it needs some more care, and
     * as these are very old, we choose to drop support for them */

    /* checks minimum requirements, most are vs3/ps3 strict requirements */
    if (!hal->get_param(hal, PIPE_CAP_SM3) ||
        hal->get_shader_param(hal, PIPE_SHADER_VERTEX,
                              PIPE_SHADER_CAP_MAX_CONST_BUFFER_SIZE) < 256 * sizeof(float[4]) ||
        hal->get_shader_param(hal, PIPE_SHADER_FRAGMENT,
                              PIPE_SHADER_CAP_MAX_CONST_BUFFER_SIZE) < 244 * sizeof(float[4]) ||
        hal->get_shader_param(hal, PIPE_SHADER_VERTEX,
                              PIPE_SHADER_CAP_MAX_TEMPS) < 32 ||
        hal->get_shader_param(hal, PIPE_SHADER_FRAGMENT,
                              PIPE_SHADER_CAP_MAX_TEMPS) < 32 ||
        hal->get_shader_param(hal, PIPE_SHADER_VERTEX,
                              PIPE_SHADER_CAP_MAX_INPUTS) < 16 ||
        hal->get_shader_param(hal, PIPE_SHADER_FRAGMENT,
                              PIPE_SHADER_CAP_MAX_INPUTS) < 10 ||
        hal->get_shader_param(hal, PIPE_SHADER_FRAGMENT,
                              PIPE_SHADER_CAP_MAX_TEXTURE_SAMPLERS) < 16) {
        ERR("Your card is not supported by Gallium Nine. Minimum requirement "
            "is >= r500, >= nv50, >= i965\n");
        return D3DERR_DRIVERINTERNALERROR;
    }
    /* for r500 */
    if (hal->get_shader_param(hal, PIPE_SHADER_VERTEX,
                              PIPE_SHADER_CAP_MAX_CONST_BUFFER_SIZE) < 276 * sizeof(float[4]) || /* we put bool and int constants with float constants */
        hal->get_shader_param(hal, PIPE_SHADER_VERTEX,
                              PIPE_SHADER_CAP_MAX_TEMPS) < 40 || /* we use some more temp registers */
        hal->get_shader_param(hal, PIPE_SHADER_FRAGMENT,
                              PIPE_SHADER_CAP_MAX_TEMPS) < 40 ||
        hal->get_shader_param(hal, PIPE_SHADER_FRAGMENT,
                              PIPE_SHADER_CAP_MAX_INPUTS) < 20) /* we don't pack inputs as much as we could */
        ERR("Your card is at the limit of Gallium Nine requirements. Some games "
            "may run into issues because requirements are too tight\n");
    return D3D_OK;
}
Beispiel #10
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;

    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;

    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);

    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;

    if (!This->resource) {
        hr = NineVolume9_AllocateData(This);
        if (FAILED(hr))
            return hr;
    }
    return D3D_OK;
}
Beispiel #11
0
HRESULT
NineVertexShader9_ctor( struct NineVertexShader9 *This,
                        struct NineUnknownParams *pParams,
                        const DWORD *pFunction, void *cso )
{
    struct NineDevice9 *device;
    struct nine_shader_info info;
    HRESULT hr;
    unsigned i;

    DBG("This=%p pParams=%p pFunction=%p cso=%p\n",
        This, pParams, pFunction, cso);

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

    if (cso) {
        This->ff_cso = cso;
        return D3D_OK;
    }

    device = This->base.device;

    info.type = PIPE_SHADER_VERTEX;
    info.byte_code = pFunction;
    info.const_i_base = NINE_CONST_I_BASE(device->max_vs_const_f) / 16;
    info.const_b_base = NINE_CONST_B_BASE(device->max_vs_const_f) / 16;
    info.sampler_mask_shadow = 0x0;
    info.sampler_ps1xtypes = 0x0;
    info.fog_enable = 0;
    info.point_size_min = 0;
    info.point_size_max = 0;
    info.swvp_on = !!(device->params.BehaviorFlags & D3DCREATE_SOFTWARE_VERTEXPROCESSING);
    info.process_vertices = false;

    hr = nine_translate_shader(device, &info);
    if (hr == D3DERR_INVALIDCALL &&
        (device->params.BehaviorFlags & D3DCREATE_MIXED_VERTEXPROCESSING)) {
        /* Retry with a swvp shader. It will require swvp to be on. */
        info.swvp_on = true;
        hr = nine_translate_shader(device, &info);
    }
    if (hr == D3DERR_INVALIDCALL)
        ERR("Encountered buggy shader\n");
    if (FAILED(hr))
        return hr;
    This->byte_code.version = info.version;
    This->swvp_only = info.swvp_on;

    This->byte_code.tokens = mem_dup(pFunction, info.byte_size);
    if (!This->byte_code.tokens)
        return E_OUTOFMEMORY;
    This->byte_code.size = info.byte_size;

    This->variant.cso = info.cso;
    This->last_cso = info.cso;
    This->last_key = (uint32_t) (info.swvp_on << 9);

    This->const_used_size = info.const_used_size;
    This->lconstf = info.lconstf;
    This->sampler_mask = info.sampler_mask;
    This->position_t = info.position_t;
    This->point_size = info.point_size;

    for (i = 0; i < info.num_inputs && i < ARRAY_SIZE(This->input_map); ++i)
        This->input_map[i].ndecl = info.input_map[i];
    This->num_inputs = i;

    return D3D_OK;
}