Commit 55223e25 authored by Zebediah Figura's avatar Zebediah Figura Committed by Alexandre Julliard

wined3d: Introduce a wined3d_streaming_buffer helper.

parent c77b23a3
......@@ -1647,3 +1647,81 @@ HRESULT CDECL wined3d_buffer_create(struct wined3d_device *device, const struct
return device->adapter->adapter_ops->adapter_create_buffer(device, desc, data, parent, parent_ops, buffer);
}
static HRESULT wined3d_streaming_buffer_prepare(struct wined3d_device *device,
struct wined3d_streaming_buffer *buffer, unsigned int min_size)
{
struct wined3d_buffer *wined3d_buffer;
struct wined3d_buffer_desc desc;
unsigned int old_size = 0;
unsigned int size;
HRESULT hr;
if (buffer->buffer)
{
old_size = buffer->buffer->resource.size;
if (old_size >= min_size)
return S_OK;
}
size = max(old_size * 2, min_size);
TRACE("Growing buffer to %u bytes.\n", size);
desc.byte_width = size;
desc.usage = WINED3DUSAGE_DYNAMIC;
desc.bind_flags = buffer->bind_flags;
desc.access = WINED3D_RESOURCE_ACCESS_GPU | WINED3D_RESOURCE_ACCESS_MAP_W;
desc.misc_flags = 0;
desc.structure_byte_stride = 0;
if (SUCCEEDED(hr = wined3d_buffer_create(device, &desc, NULL, NULL, &wined3d_null_parent_ops, &wined3d_buffer)))
{
if (buffer->buffer)
wined3d_buffer_decref(buffer->buffer);
buffer->buffer = wined3d_buffer;
buffer->pos = 0;
}
return hr;
}
HRESULT CDECL wined3d_streaming_buffer_upload(struct wined3d_device *device, struct wined3d_streaming_buffer *buffer,
const void *data, unsigned int size, unsigned int stride, unsigned int *ret_pos)
{
unsigned int map_flags = WINED3D_MAP_WRITE;
struct wined3d_resource *resource;
struct wined3d_map_desc map_desc;
unsigned int pos, align;
struct wined3d_box box;
HRESULT hr;
TRACE("device %p, buffer %p, data %p, size %u, stride %u, ret_pos %p.\n",
device, buffer, data, size, stride, ret_pos);
if (FAILED(hr = wined3d_streaming_buffer_prepare(device, buffer, size)))
return hr;
resource = &buffer->buffer->resource;
pos = buffer->pos;
if ((align = pos % stride))
align = stride - align;
if (pos + size + align > resource->size)
{
pos = 0;
map_flags |= WINED3D_MAP_DISCARD;
}
else
{
pos += align;
map_flags |= WINED3D_MAP_NOOVERWRITE;
}
wined3d_box_set(&box, pos, 0, pos + size, 1, 0, 1);
if (SUCCEEDED(hr = wined3d_resource_map(resource, 0, &map_desc, &box, map_flags)))
{
memcpy(map_desc.data, data, size);
wined3d_resource_unmap(resource, 0);
*ret_pos = pos;
buffer->pos = pos + size;
}
return hr;
}
......@@ -260,6 +260,8 @@
@ cdecl wined3d_stateblock_set_vs_consts_f(ptr long long ptr)
@ cdecl wined3d_stateblock_set_vs_consts_i(ptr long long ptr)
@ cdecl wined3d_streaming_buffer_upload(ptr ptr ptr long long ptr)
@ cdecl wined3d_swapchain_create(ptr ptr ptr ptr ptr ptr)
@ cdecl wined3d_swapchain_decref(ptr)
@ cdecl wined3d_swapchain_get_back_buffer(ptr long)
......
......@@ -2320,6 +2320,13 @@ struct wined3d_private_data
typedef HRESULT (CDECL *wined3d_device_reset_cb)(struct wined3d_resource *resource);
struct wined3d_streaming_buffer
{
struct wined3d_buffer *buffer;
unsigned int pos;
unsigned int bind_flags;
};
void __stdcall wined3d_mutex_lock(void);
void __stdcall wined3d_mutex_unlock(void);
......@@ -2825,6 +2832,9 @@ HRESULT __cdecl wined3d_stateblock_set_vs_consts_f(struct wined3d_stateblock *st
HRESULT __cdecl wined3d_stateblock_set_vs_consts_i(struct wined3d_stateblock *stateblock,
unsigned int start_idx, unsigned int count, const struct wined3d_ivec4 *constants);
HRESULT __cdecl wined3d_streaming_buffer_upload(struct wined3d_device *device, struct wined3d_streaming_buffer *buffer,
const void *data, unsigned int size, unsigned int stride, unsigned int *pos);
HRESULT __cdecl wined3d_swapchain_create(struct wined3d_device *device,
struct wined3d_swapchain_desc *desc, struct wined3d_swapchain_state_parent *state_parent,
void *parent, const struct wined3d_parent_ops *parent_ops,
......@@ -2922,6 +2932,20 @@ ULONG __cdecl wined3d_vertex_declaration_incref(struct wined3d_vertex_declaratio
HRESULT __cdecl wined3d_extract_shader_input_signature_from_dxbc(struct wined3d_shader_signature *signature,
const void *byte_code, SIZE_T byte_code_size);
static inline void wined3d_streaming_buffer_init(struct wined3d_streaming_buffer *buffer, unsigned int bind_flags)
{
memset(buffer, 0, sizeof(*buffer));
buffer->bind_flags = bind_flags;
}
static inline void wined3d_streaming_buffer_cleanup(struct wined3d_streaming_buffer *buffer)
{
if (buffer->buffer)
wined3d_buffer_decref(buffer->buffer);
buffer->buffer = NULL;
buffer->pos = 0;
}
/* Return the integer base-2 logarithm of x. Undefined for x == 0. */
static inline unsigned int wined3d_log2i(unsigned int x)
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment