Пример #1
0
HRESULT vertexbuffer_init(struct d3d8_vertexbuffer *buffer, struct d3d8_device *device,
        UINT size, DWORD usage, DWORD fvf, D3DPOOL pool)
{
    const struct wined3d_parent_ops *parent_ops = &d3d8_null_wined3d_parent_ops;
    struct wined3d_buffer_desc desc;
    HRESULT hr;

    if (pool == D3DPOOL_SCRATCH)
    {
        WARN("Vertex buffer with D3DPOOL_SCRATCH requested.\n");
        return D3DERR_INVALIDCALL;
    }

    /* In d3d8, buffers can't be used as rendertarget or depth/stencil buffer. */
    if (usage & (D3DUSAGE_RENDERTARGET | D3DUSAGE_DEPTHSTENCIL))
        return D3DERR_INVALIDCALL;

    buffer->IDirect3DVertexBuffer8_iface.lpVtbl = &Direct3DVertexBuffer8_Vtbl;
    d3d8_resource_init(&buffer->resource);
    buffer->fvf = fvf;
    buffer->usage = usage;

    desc.byte_width = size;
    desc.usage = usage & WINED3DUSAGE_MASK;
    desc.bind_flags = 0;
    desc.access = wined3daccess_from_d3dpool(pool, usage) | map_access_from_usage(usage);
    /* Buffers are always readable. */
    if (pool != D3DPOOL_DEFAULT)
        desc.access |= WINED3D_RESOURCE_ACCESS_MAP_R | WINED3D_RESOURCE_ACCESS_MAP_W;
    desc.misc_flags = 0;
    desc.structure_byte_stride = 0;

    if (desc.access & WINED3D_RESOURCE_ACCESS_GPU)
    {
        desc.bind_flags = WINED3D_BIND_VERTEX_BUFFER;
        parent_ops = &d3d8_vertexbuffer_wined3d_parent_ops;
    }

    wined3d_mutex_lock();
    hr = wined3d_buffer_create(device->wined3d_device, &desc, NULL, buffer, parent_ops, &buffer->wined3d_buffer);
    if (SUCCEEDED(hr) && !(desc.access & WINED3D_RESOURCE_ACCESS_GPU))
    {
        desc.bind_flags = WINED3D_BIND_VERTEX_BUFFER;
        desc.access = WINED3D_RESOURCE_ACCESS_GPU;
        if (FAILED(hr = wined3d_buffer_create(device->wined3d_device, &desc, NULL, buffer,
                &d3d8_vertexbuffer_wined3d_parent_ops, &buffer->draw_buffer)))
            wined3d_buffer_decref(buffer->wined3d_buffer);
    }
    wined3d_mutex_unlock();
    if (FAILED(hr))
    {
        WARN("Failed to create wined3d buffer, hr %#x.\n", hr);
        return hr;
    }

    buffer->parent_device = &device->IDirect3DDevice8_iface;
    IDirect3DDevice8_AddRef(buffer->parent_device);

    return D3D_OK;
}
Пример #2
0
HRESULT indexbuffer_init(struct d3d8_indexbuffer *buffer, struct d3d8_device *device,
        UINT size, DWORD usage, D3DFORMAT format, D3DPOOL pool)
{
    const struct wined3d_parent_ops *parent_ops = &d3d8_null_wined3d_parent_ops;
    struct wined3d_buffer_desc desc;
    HRESULT hr;

    if (pool == D3DPOOL_SCRATCH)
        return D3DERR_INVALIDCALL;

    /* In d3d8, buffers can't be used as rendertarget or depth/stencil buffer. */
    if (usage & (D3DUSAGE_RENDERTARGET | D3DUSAGE_DEPTHSTENCIL))
        return D3DERR_INVALIDCALL;

    desc.byte_width = size;
    desc.usage = (usage & WINED3DUSAGE_MASK) | WINED3DUSAGE_STATICDECL;
    desc.bind_flags = 0;
    desc.access = wined3daccess_from_d3dpool(pool, usage)
            | WINED3D_RESOURCE_ACCESS_MAP_R | WINED3D_RESOURCE_ACCESS_MAP_W;
    desc.misc_flags = 0;
    desc.structure_byte_stride = 0;

    if (desc.access & WINED3D_RESOURCE_ACCESS_GPU)
    {
        desc.bind_flags = WINED3D_BIND_INDEX_BUFFER;
        parent_ops = &d3d8_indexbuffer_wined3d_parent_ops;
    }

    buffer->IDirect3DIndexBuffer8_iface.lpVtbl = &d3d8_indexbuffer_vtbl;
    d3d8_resource_init(&buffer->resource);
    buffer->format = wined3dformat_from_d3dformat(format);

    wined3d_mutex_lock();
    hr = wined3d_buffer_create(device->wined3d_device, &desc, NULL, buffer, parent_ops, &buffer->wined3d_buffer);
    if (SUCCEEDED(hr) && !(desc.access & WINED3D_RESOURCE_ACCESS_GPU))
    {
        desc.bind_flags = WINED3D_BIND_INDEX_BUFFER;
        desc.access = WINED3D_RESOURCE_ACCESS_GPU;
        if (FAILED(hr = wined3d_buffer_create(device->wined3d_device, &desc, NULL, buffer,
                &d3d8_indexbuffer_wined3d_parent_ops, &buffer->draw_buffer)))
            wined3d_buffer_decref(buffer->wined3d_buffer);
    }
    wined3d_mutex_unlock();
    if (FAILED(hr))
    {
        WARN("Failed to create wined3d buffer, hr %#x.\n", hr);
        return hr;
    }

    buffer->parent_device = &device->IDirect3DDevice8_iface;
    IDirect3DDevice8_AddRef(buffer->parent_device);

    return D3D_OK;
}
Пример #3
0
HRESULT d3d10_buffer_init(struct d3d10_buffer *buffer, struct d3d10_device *device,
        const D3D10_BUFFER_DESC *desc, const D3D10_SUBRESOURCE_DATA *data)
{
    struct wined3d_buffer_desc wined3d_desc;
    HRESULT hr;

    buffer->vtbl = &d3d10_buffer_vtbl;
    buffer->refcount = 1;

    FIXME("Implement DXGI<->wined3d usage conversion\n");

    wined3d_desc.byte_width = desc->ByteWidth;
    wined3d_desc.usage = desc->Usage;
    wined3d_desc.bind_flags = desc->BindFlags;
    wined3d_desc.cpu_access_flags = desc->CPUAccessFlags;
    wined3d_desc.misc_flags = desc->MiscFlags;

    hr = wined3d_buffer_create(device->wined3d_device, &wined3d_desc,
            data ? data->pSysMem : NULL, buffer, &d3d10_buffer_wined3d_parent_ops,
            &buffer->wined3d_buffer);
    if (FAILED(hr))
    {
        WARN("Failed to create wined3d buffer, hr %#x.\n", hr);
        return hr;
    }

    return S_OK;
}
Пример #4
0
static HRESULT d3d_buffer_init(struct d3d_buffer *buffer, struct d3d_device *device,
        const D3D11_BUFFER_DESC *desc, const D3D11_SUBRESOURCE_DATA *data)
{
    struct wined3d_buffer_desc wined3d_desc;
    HRESULT hr;

    buffer->ID3D11Buffer_iface.lpVtbl = &d3d11_buffer_vtbl;
    buffer->ID3D10Buffer_iface.lpVtbl = &d3d10_buffer_vtbl;
    buffer->refcount = 1;
    buffer->desc = *desc;

    if (!validate_buffer_desc(&buffer->desc, device->feature_level))
        return E_INVALIDARG;

    wined3d_desc.byte_width = buffer->desc.ByteWidth;
    wined3d_desc.usage = wined3d_usage_from_d3d11(0, buffer->desc.Usage);
    wined3d_desc.bind_flags = buffer->desc.BindFlags;
    wined3d_desc.access = wined3d_access_from_d3d11(buffer->desc.Usage, buffer->desc.CPUAccessFlags);
    wined3d_desc.misc_flags = buffer->desc.MiscFlags;
    wined3d_desc.structure_byte_stride = buffer->desc.StructureByteStride;

    wined3d_mutex_lock();
    wined3d_private_store_init(&buffer->private_store);

    if (FAILED(hr = wined3d_buffer_create(device->wined3d_device, &wined3d_desc,
            (const struct wined3d_sub_resource_data *)data, buffer,
            &d3d_buffer_wined3d_parent_ops, &buffer->wined3d_buffer)))
    {
        WARN("Failed to create wined3d buffer, hr %#x.\n", hr);
        wined3d_private_store_cleanup(&buffer->private_store);
        wined3d_mutex_unlock();
        return hr;
    }
    wined3d_mutex_unlock();

    ID3D11Device2_AddRef(buffer->device = &device->ID3D11Device2_iface);

    return S_OK;
}
Пример #5
0
static HRESULT d3d_buffer_init(struct d3d_buffer *buffer, struct d3d_device *device,
                               const D3D11_BUFFER_DESC *desc, const D3D11_SUBRESOURCE_DATA *data)
{
    struct wined3d_buffer_desc wined3d_desc;
    HRESULT hr;

    buffer->ID3D11Buffer_iface.lpVtbl = &d3d11_buffer_vtbl;
    buffer->ID3D10Buffer_iface.lpVtbl = &d3d10_buffer_vtbl;
    buffer->refcount = 1;
    wined3d_mutex_lock();
    wined3d_private_store_init(&buffer->private_store);
    buffer->desc = *desc;

    wined3d_desc.byte_width = desc->ByteWidth;
    wined3d_desc.usage = wined3d_usage_from_d3d11(0, desc->Usage);
    wined3d_desc.bind_flags = desc->BindFlags;
    wined3d_desc.cpu_access_flags = desc->CPUAccessFlags;
    wined3d_desc.misc_flags = desc->MiscFlags;

    if (desc->StructureByteStride)
        FIXME("Ignoring structure byte stride %u.\n", desc->StructureByteStride);

    if (FAILED(hr = wined3d_buffer_create(device->wined3d_device, &wined3d_desc,
                                          (const struct wined3d_sub_resource_data *)data, buffer,
                                          &d3d10_buffer_wined3d_parent_ops, &buffer->wined3d_buffer)))
    {
        WARN("Failed to create wined3d buffer, hr %#x.\n", hr);
        wined3d_private_store_cleanup(&buffer->private_store);
        wined3d_mutex_unlock();
        return hr;
    }
    wined3d_mutex_unlock();

    buffer->device = &device->ID3D11Device_iface;
    ID3D11Device_AddRef(buffer->device);

    return S_OK;
}
Пример #6
0
static HRESULT d3d_buffer_init(struct d3d_buffer *buffer, struct d3d_device *device,
        const D3D11_BUFFER_DESC *desc, const D3D11_SUBRESOURCE_DATA *data)
{
    struct wined3d_buffer_desc wined3d_desc;
    HRESULT hr;

    buffer->ID3D11Buffer_iface.lpVtbl = &d3d11_buffer_vtbl;
    buffer->ID3D10Buffer_iface.lpVtbl = &d3d10_buffer_vtbl;
    buffer->refcount = 1;
    wined3d_mutex_lock();
    wined3d_private_store_init(&buffer->private_store);
    buffer->desc = *desc;

    if (buffer->desc.MiscFlags & D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS)
    {
        if (buffer->desc.MiscFlags & D3D11_RESOURCE_MISC_BUFFER_STRUCTURED)
        {
            WARN("Raw and structure buffers are mutually exclusive.\n");
            return E_INVALIDARG;
        }
        if (!(buffer->desc.BindFlags & (D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_UNORDERED_ACCESS)))
        {
            WARN("Invalid bind flags %#x for raw buffer.\n", buffer->desc.BindFlags);
            return E_INVALIDARG;
        }
    }

    if (buffer->desc.MiscFlags & D3D11_RESOURCE_MISC_BUFFER_STRUCTURED)
    {
        if (!buffer->desc.StructureByteStride || buffer->desc.StructureByteStride % 4)
        {
            WARN("Invalid structure byte stride %u.\n", buffer->desc.StructureByteStride);
            return E_INVALIDARG;
        }
        if (buffer->desc.ByteWidth % buffer->desc.StructureByteStride)
        {
            WARN("Byte width %u is not divisible by structure byte stride %u.\n",
                    buffer->desc.ByteWidth, buffer->desc.StructureByteStride);
            return E_INVALIDARG;
        }
    }
    else
    {
        buffer->desc.StructureByteStride = 0;
    }

    wined3d_desc.byte_width = buffer->desc.ByteWidth;
    wined3d_desc.usage = wined3d_usage_from_d3d11(0, buffer->desc.Usage);
    wined3d_desc.bind_flags = buffer->desc.BindFlags;
    wined3d_desc.cpu_access_flags = buffer->desc.CPUAccessFlags;
    wined3d_desc.misc_flags = buffer->desc.MiscFlags;

    if (buffer->desc.StructureByteStride)
        FIXME("Ignoring structure byte stride %u.\n", buffer->desc.StructureByteStride);

    if (FAILED(hr = wined3d_buffer_create(device->wined3d_device, &wined3d_desc,
            (const struct wined3d_sub_resource_data *)data, buffer,
            &d3d_buffer_wined3d_parent_ops, &buffer->wined3d_buffer)))
    {
        WARN("Failed to create wined3d buffer, hr %#x.\n", hr);
        wined3d_private_store_cleanup(&buffer->private_store);
        wined3d_mutex_unlock();
        return hr;
    }
    wined3d_mutex_unlock();

    buffer->device = &device->ID3D11Device_iface;
    ID3D11Device_AddRef(buffer->device);

    return S_OK;
}