058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync/*
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * Copyright 2002-2005 Jason Edmeades
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * Copyright 2002-2005 Raphael Junqueira
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * Copyright 2004 Christian Costa
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * Copyright 2005 Oliver Stieber
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * Copyright 2007-2010 Stefan Dösinger for CodeWeavers
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * Copyright 2009-2010 Henri Verbeet for CodeWeavers
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync *
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * This library is free software; you can redistribute it and/or
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * modify it under the terms of the GNU Lesser General Public
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * License as published by the Free Software Foundation; either
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * version 2.1 of the License, or (at your option) any later version.
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync *
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * This library is distributed in the hope that it will be useful,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * but WITHOUT ANY WARRANTY; without even the implied warranty of
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * Lesser General Public License for more details.
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync *
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * You should have received a copy of the GNU Lesser General Public
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * License along with this library; if not, write to the Free Software
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync *
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
4237d5a79f48789aacc67dc43378d2d7813a39f4vboxsync/*
4237d5a79f48789aacc67dc43378d2d7813a39f4vboxsync * Oracle LGPL Disclaimer: For the avoidance of doubt, except that if any license choice
4237d5a79f48789aacc67dc43378d2d7813a39f4vboxsync * other than GPL or LGPL is available it will apply instead, Oracle elects to use only
4237d5a79f48789aacc67dc43378d2d7813a39f4vboxsync * the Lesser General Public License version 2.1 (LGPLv2) at this time for any software where
4237d5a79f48789aacc67dc43378d2d7813a39f4vboxsync * a choice of LGPL license versions is made available with the language indicating
4237d5a79f48789aacc67dc43378d2d7813a39f4vboxsync * that LGPLv2 or any later version may be used, or where a choice of which version
4237d5a79f48789aacc67dc43378d2d7813a39f4vboxsync * of the LGPL is applied is otherwise unspecified.
4237d5a79f48789aacc67dc43378d2d7813a39f4vboxsync */
4237d5a79f48789aacc67dc43378d2d7813a39f4vboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync#include "config.h"
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync#include "wine/port.h"
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync#include "wined3d_private.h"
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncWINE_DEFAULT_DEBUG_CHANNEL(d3d);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync#define VB_MAXDECLCHANGES 100 /* After that number of decl changes we stop converting */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync#define VB_RESETDECLCHANGE 1000 /* Reset the decl changecount after that number of draws */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync#define VB_MAXFULLCONVERSIONS 5 /* Number of full conversions before we stop converting */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync#define VB_RESETFULLCONVS 20 /* Reset full conversion counts after that number of draws */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstatic inline BOOL buffer_add_dirty_area(struct wined3d_buffer *This, UINT offset, UINT size)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!This->buffer_object) return TRUE;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (This->maps_size <= This->modified_areas)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync void *new = HeapReAlloc(GetProcessHeap(), 0, This->maps,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync This->maps_size * 2 * sizeof(*This->maps));
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!new)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync ERR("Out of memory\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return FALSE;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync else
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync This->maps = new;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync This->maps_size *= 2;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if(offset > This->resource.size || offset + size > This->resource.size)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync WARN("Invalid range dirtified, marking entire buffer dirty\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync offset = 0;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync size = This->resource.size;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync else if(!offset && !size)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync size = This->resource.size;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync This->maps[This->modified_areas].offset = offset;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync This->maps[This->modified_areas].size = size;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync This->modified_areas++;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return TRUE;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstatic inline void buffer_clear_dirty_areas(struct wined3d_buffer *This)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync This->modified_areas = 0;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstatic BOOL buffer_is_dirty(const struct wined3d_buffer *buffer)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return !!buffer->modified_areas;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstatic BOOL buffer_is_fully_dirty(const struct wined3d_buffer *buffer)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync unsigned int i;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync for (i = 0; i < buffer->modified_areas; ++i)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!buffer->maps[i].offset && buffer->maps[i].size == buffer->resource.size)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return TRUE;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return FALSE;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync/* Context activation is done by the caller */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstatic void delete_gl_buffer(struct wined3d_buffer *This, const struct wined3d_gl_info *gl_info)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if(!This->buffer_object) return;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync GL_EXTCALL(glDeleteBuffersARB(1, &This->buffer_object));
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync checkGLcall("glDeleteBuffersARB");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync This->buffer_object = 0;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if(This->query)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_event_query_destroy(This->query);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync This->query = NULL;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync This->flags &= ~WINED3D_BUFFER_APPLESYNC;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync/* Context activation is done by the caller. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstatic void buffer_create_buffer_object(struct wined3d_buffer *This, const struct wined3d_gl_info *gl_info)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync GLenum gl_usage = GL_STATIC_DRAW_ARB;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync GLenum error;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("Creating an OpenGL vertex buffer object for wined3d_buffer %p with usage %s.\n",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync This, debug_d3dusage(This->resource.usage));
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Make sure that the gl error is cleared. Do not use checkGLcall
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * here because checkGLcall just prints a fixme and continues. However,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * if an error during VBO creation occurs we can fall back to non-vbo operation
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * with full functionality(but performance loss)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync while (gl_info->gl_ops.gl.p_glGetError() != GL_NO_ERROR);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Basically the FVF parameter passed to CreateVertexBuffer is no good.
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * The vertex declaration from the device determines how the data in the
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * buffer is interpreted. This means that on each draw call the buffer has
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * to be verified to check if the rhw and color values are in the correct
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * format. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync GL_EXTCALL(glGenBuffersARB(1, &This->buffer_object));
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync error = gl_info->gl_ops.gl.p_glGetError();
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!This->buffer_object || error != GL_NO_ERROR)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync ERR("Failed to create a VBO with error %s (%#x)\n", debug_glerror(error), error);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync goto fail;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (This->buffer_type_hint == GL_ELEMENT_ARRAY_BUFFER_ARB)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device_invalidate_state(This->resource.device, STATE_INDEXBUFFER);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync GL_EXTCALL(glBindBufferARB(This->buffer_type_hint, This->buffer_object));
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync error = gl_info->gl_ops.gl.p_glGetError();
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (error != GL_NO_ERROR)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync ERR("Failed to bind the VBO with error %s (%#x)\n", debug_glerror(error), error);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync goto fail;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (This->resource.usage & WINED3DUSAGE_DYNAMIC)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("Buffer has WINED3DUSAGE_DYNAMIC set.\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync gl_usage = GL_STREAM_DRAW_ARB;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if(gl_info->supported[APPLE_FLUSH_BUFFER_RANGE])
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync GL_EXTCALL(glBufferParameteriAPPLE(This->buffer_type_hint, GL_BUFFER_FLUSHING_UNMAP_APPLE, GL_FALSE));
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync checkGLcall("glBufferParameteriAPPLE(This->buffer_type_hint, GL_BUFFER_FLUSHING_UNMAP_APPLE, GL_FALSE)");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync This->flags |= WINED3D_BUFFER_FLUSH;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync GL_EXTCALL(glBufferParameteriAPPLE(This->buffer_type_hint, GL_BUFFER_SERIALIZED_MODIFY_APPLE, GL_FALSE));
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync checkGLcall("glBufferParameteriAPPLE(This->buffer_type_hint, GL_BUFFER_SERIALIZED_MODIFY_APPLE, GL_FALSE)");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync This->flags |= WINED3D_BUFFER_APPLESYNC;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* No setup is needed here for GL_ARB_map_buffer_range */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Reserve memory for the buffer. The amount of data won't change
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * so we are safe with calling glBufferData once and
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * calling glBufferSubData on updates. Upload the actual data in case
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * we're not double buffering, so we can release the heap mem afterwards
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync GL_EXTCALL(glBufferDataARB(This->buffer_type_hint, This->resource.size, This->resource.allocatedMemory, gl_usage));
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync error = gl_info->gl_ops.gl.p_glGetError();
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (error != GL_NO_ERROR)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync ERR("glBufferDataARB failed with error %s (%#x)\n", debug_glerror(error), error);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync goto fail;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync This->buffer_object_size = This->resource.size;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync This->buffer_object_usage = gl_usage;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if(This->flags & WINED3D_BUFFER_DOUBLEBUFFER)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if(!buffer_add_dirty_area(This, 0, 0))
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync ERR("buffer_add_dirty_area failed, this is not expected\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync goto fail;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync else
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync HeapFree(GetProcessHeap(), 0, This->resource.heapMemory);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync This->resource.allocatedMemory = NULL;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync This->resource.heapMemory = NULL;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncfail:
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Clean up all vbo init, but continue because we can work without a vbo :-) */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync ERR("Failed to create a vertex buffer object. Continuing, but performance issues may occur\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync delete_gl_buffer(This, gl_info);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync buffer_clear_dirty_areas(This);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstatic BOOL buffer_process_converted_attribute(struct wined3d_buffer *This,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync const enum wined3d_buffer_conversion_type conversion_type,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync const struct wined3d_stream_info_element *attrib, DWORD *stride_this_run
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync#ifdef VBOX_WITH_WINE_FIX_BUFOFFSET
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync , DWORD *offset_this_run
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync#endif
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync )
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync DWORD attrib_size;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync BOOL ret = FALSE;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync unsigned int i;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync#ifndef VBOX_WITH_WINE_FIX_BUFOFFSET
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync DWORD_PTR data;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync#else
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync UINT stream_offset = (UINT)(attrib->data.addr - attrib->offset);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync#endif
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Check for some valid situations which cause us pain. One is if the buffer is used for
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * constant attributes(stride = 0), the other one is if the buffer is used on two streams
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * with different strides. In the 2nd case we might have to drop conversion entirely,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * it is possible that the same bytes are once read as FLOAT2 and once as UBYTE4N.
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!attrib->stride)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync FIXME("%s used with stride 0, let's hope we get the vertex stride from somewhere else\n",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync debug_d3dformat(attrib->format->id));
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync#ifndef VBOX_WITH_WINE_FIX_BUFOFFSET
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync else if(attrib->stride != *stride_this_run && *stride_this_run)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync FIXME("Got two concurrent strides, %d and %d\n", attrib->stride, *stride_this_run);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync#else
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync else if((attrib->stride != *stride_this_run && *stride_this_run)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync || (stream_offset != *offset_this_run && *offset_this_run))
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync ERR("Got two concurrent strides, %d and %d\n", attrib->stride, *stride_this_run);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync#endif
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync else
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync *stride_this_run = attrib->stride;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync#ifdef VBOX_WITH_WINE_FIX_BUFOFFSET
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync *offset_this_run = stream_offset;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (This->stride != *stride_this_run
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync || This->offset != *offset_this_run)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync#else
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (This->stride != *stride_this_run)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync#endif
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* We rely that this happens only on the first converted attribute that is found,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * if at all. See above check
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("Reconverting because converted attributes occur, and the stride changed\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync This->stride = *stride_this_run;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync#ifdef VBOX_WITH_WINE_FIX_BUFOFFSET
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync This->offset = *offset_this_run;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync#endif
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync HeapFree(GetProcessHeap(), HEAP_ZERO_MEMORY, This->conversion_map);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync This->conversion_map = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync sizeof(*This->conversion_map) * This->stride);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync ret = TRUE;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync#ifndef VBOX_WITH_WINE_FIX_BUFOFFSET
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync data = ((DWORD_PTR)attrib->data.addr) % This->stride;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync#endif
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync attrib_size = attrib->format->component_count * attrib->format->component_size;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync for (i = 0; i < attrib_size; ++i)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync#ifndef VBOX_WITH_WINE_FIX_BUFOFFSET
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync DWORD_PTR idx = (data + i) % This->stride;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync#else
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync DWORD_PTR idx = attrib->offset;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync#endif
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (This->conversion_map[idx] != conversion_type)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("Byte %ld in vertex changed\n", idx);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("It was type %d, is %d now\n", This->conversion_map[idx], conversion_type);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync ret = TRUE;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync This->conversion_map[idx] = conversion_type;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return ret;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstatic BOOL buffer_check_attribute(struct wined3d_buffer *This, const struct wined3d_stream_info *si,
1675f41731e9e75ac43352afd2b690c08795b032vboxsync UINT attrib_idx, const BOOL check_d3dcolor, const BOOL check_position, const BOOL is_ffp_color,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync DWORD *stride_this_run
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync#ifdef VBOX_WITH_WINE_FIX_BUFOFFSET
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync , DWORD *offset_this_run
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync#endif
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync )
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync const struct wined3d_stream_info_element *attrib = &si->elements[attrib_idx];
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync enum wined3d_format_id format;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync BOOL ret = FALSE;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Ignore attributes that do not have our vbo. After that check we can be sure that the attribute is
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * there, on nonexistent attribs the vbo is 0.
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!(si->use_map & (1 << attrib_idx))
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync || attrib->data.buffer_object != This->buffer_object)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return FALSE;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync format = attrib->format->id;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Look for newly appeared conversion */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (check_d3dcolor && format == WINED3DFMT_B8G8R8A8_UNORM)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync ret = buffer_process_converted_attribute(This, CONV_D3DCOLOR, attrib, stride_this_run
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync#ifdef VBOX_WITH_WINE_FIX_BUFOFFSET
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync , offset_this_run
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync#endif
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync );
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!is_ffp_color) FIXME("Test for non-color fixed function WINED3DFMT_B8G8R8A8_UNORM format\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
1675f41731e9e75ac43352afd2b690c08795b032vboxsync else if (check_position && si->position_transformed)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (format != WINED3DFMT_R32G32B32A32_FLOAT)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync FIXME("Unexpected format %s for transformed position.\n", debug_d3dformat(format));
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return FALSE;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync ret = buffer_process_converted_attribute(This, CONV_POSITIONT, attrib, stride_this_run
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync#ifdef VBOX_WITH_WINE_FIX_BUFOFFSET
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync , offset_this_run
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync#endif
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync );
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync else if (This->conversion_map)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync ret = buffer_process_converted_attribute(This, CONV_NONE, attrib, stride_this_run
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync#ifdef VBOX_WITH_WINE_FIX_BUFOFFSET
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync , offset_this_run
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync#endif
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync );
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return ret;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstatic BOOL buffer_find_decl(struct wined3d_buffer *This)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_device *device = This->resource.device;
1675f41731e9e75ac43352afd2b690c08795b032vboxsync const struct wined3d_adapter *adapter = device->adapter;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync const struct wined3d_stream_info *si = &device->stream_info;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync const struct wined3d_state *state = &device->stateBlock->state;
1675f41731e9e75ac43352afd2b690c08795b032vboxsync BOOL support_d3dcolor = adapter->gl_info.supported[ARB_VERTEX_ARRAY_BGRA];
1675f41731e9e75ac43352afd2b690c08795b032vboxsync BOOL support_xyzrhw = adapter->d3d_info.xyzrhw;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync UINT stride_this_run = 0;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync#ifdef VBOX_WITH_WINE_FIX_BUFOFFSET
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync UINT offset_this_run = 0;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync#endif
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync BOOL ret = FALSE;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* In d3d7 the vertex buffer declaration NEVER changes because it is stored in the d3d7 vertex buffer.
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * Once we have our declaration there is no need to look it up again. Index buffers also never need
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * conversion, so once the (empty) conversion structure is created don't bother checking again
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (This->flags & WINED3D_BUFFER_HASDESC)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if(This->resource.usage & WINED3DUSAGE_STATICDECL) return FALSE;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (use_vs(state))
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("Vertex shaders used, no VBO conversion is needed\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if(This->conversion_map)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync HeapFree(GetProcessHeap(), 0, This->conversion_map);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync This->conversion_map = NULL;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync This->stride = 0;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return TRUE;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return FALSE;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("Finding vertex buffer conversion information\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Certain declaration types need some fixups before we can pass them to
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * opengl. This means D3DCOLOR attributes with fixed function vertex
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * processing, FLOAT4 POSITIONT with fixed function, and FLOAT16 if
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * GL_ARB_half_float_vertex is not supported.
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync *
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * Note for d3d8 and d3d9:
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * The vertex buffer FVF doesn't help with finding them, we have to use
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * the decoded vertex declaration and pick the things that concern the
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * current buffer. A problem with this is that this can change between
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * draws, so we have to validate the information and reprocess the buffer
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * if it changes, and avoid false positives for performance reasons.
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * WineD3D doesn't even know the vertex buffer any more, it is managed
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * by the client libraries and passed to SetStreamSource and ProcessVertices
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * as needed.
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync *
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * We have to distinguish between vertex shaders and fixed function to
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * pick the way we access the strided vertex information.
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync *
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * This code sets up a per-byte array with the size of the detected
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * stride of the arrays in the buffer. For each byte we have a field
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * that marks the conversion needed on this byte. For example, the
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * following declaration with fixed function vertex processing:
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync *
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * POSITIONT, FLOAT4
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * NORMAL, FLOAT3
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * DIFFUSE, FLOAT16_4
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * SPECULAR, D3DCOLOR
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync *
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * Will result in
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * { POSITIONT }{ NORMAL }{ DIFFUSE }{SPECULAR }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * [P][P][P][P][P][P][P][P][P][P][P][P][P][P][P][P][0][0][0][0][0][0][0][0][0][0][0][0][F][F][F][F][F][F][F][F][C][C][C][C]
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync *
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * Where in this example map P means 4 component position conversion, 0
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * means no conversion, F means FLOAT16_2 conversion and C means D3DCOLOR
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * conversion (red / blue swizzle).
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync *
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * If we're doing conversion and the stride changes we have to reconvert
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * the whole buffer. Note that we do not mind if the semantic changes,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * we only care for the conversion type. So if the NORMAL is replaced
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * with a TEXCOORD, nothing has to be done, or if the DIFFUSE is replaced
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * with a D3DCOLOR BLENDWEIGHT we can happily dismiss the change. Some
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * conversion types depend on the semantic as well, for example a FLOAT4
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * texcoord needs no conversion while a FLOAT4 positiont needs one
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync ret = buffer_check_attribute(This, si, WINED3D_FFP_POSITION,
1675f41731e9e75ac43352afd2b690c08795b032vboxsync TRUE, !support_xyzrhw, FALSE, &stride_this_run
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync#ifdef VBOX_WITH_WINE_FIX_BUFOFFSET
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync , &offset_this_run
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync#endif
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync ) || ret;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync ret = buffer_check_attribute(This, si, WINED3D_FFP_NORMAL,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRUE, FALSE, FALSE, &stride_this_run
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync#ifdef VBOX_WITH_WINE_FIX_BUFOFFSET
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync , &offset_this_run
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync#endif
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync ) || ret;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync ret = buffer_check_attribute(This, si, WINED3D_FFP_DIFFUSE,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync !support_d3dcolor, FALSE, TRUE, &stride_this_run
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync#ifdef VBOX_WITH_WINE_FIX_BUFOFFSET
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync , &offset_this_run
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync#endif
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync ) || ret;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync ret = buffer_check_attribute(This, si, WINED3D_FFP_SPECULAR,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync !support_d3dcolor, FALSE, TRUE, &stride_this_run
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync#ifdef VBOX_WITH_WINE_FIX_BUFOFFSET
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync , &offset_this_run
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync#endif
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync ) || ret;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync ret = buffer_check_attribute(This, si, WINED3D_FFP_TEXCOORD0,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRUE, FALSE, FALSE, &stride_this_run
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync#ifdef VBOX_WITH_WINE_FIX_BUFOFFSET
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync , &offset_this_run
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync#endif
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync ) || ret;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync ret = buffer_check_attribute(This, si, WINED3D_FFP_TEXCOORD1,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRUE, FALSE, FALSE, &stride_this_run
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync#ifdef VBOX_WITH_WINE_FIX_BUFOFFSET
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync , &offset_this_run
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync#endif
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync ) || ret;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync ret = buffer_check_attribute(This, si, WINED3D_FFP_TEXCOORD2,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRUE, FALSE, FALSE, &stride_this_run
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync#ifdef VBOX_WITH_WINE_FIX_BUFOFFSET
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync , &offset_this_run
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync#endif
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync ) || ret;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync ret = buffer_check_attribute(This, si, WINED3D_FFP_TEXCOORD3,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRUE, FALSE, FALSE, &stride_this_run
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync#ifdef VBOX_WITH_WINE_FIX_BUFOFFSET
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync , &offset_this_run
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync#endif
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync ) || ret;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync ret = buffer_check_attribute(This, si, WINED3D_FFP_TEXCOORD4,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRUE, FALSE, FALSE, &stride_this_run
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync#ifdef VBOX_WITH_WINE_FIX_BUFOFFSET
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync , &offset_this_run
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync#endif
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync ) || ret;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync ret = buffer_check_attribute(This, si, WINED3D_FFP_TEXCOORD5,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRUE, FALSE, FALSE, &stride_this_run
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync#ifdef VBOX_WITH_WINE_FIX_BUFOFFSET
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync , &offset_this_run
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync#endif
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync ) || ret;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync ret = buffer_check_attribute(This, si, WINED3D_FFP_TEXCOORD6,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRUE, FALSE, FALSE, &stride_this_run
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync#ifdef VBOX_WITH_WINE_FIX_BUFOFFSET
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync , &offset_this_run
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync#endif
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync ) || ret;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync ret = buffer_check_attribute(This, si, WINED3D_FFP_TEXCOORD7,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRUE, FALSE, FALSE, &stride_this_run
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync#ifdef VBOX_WITH_WINE_FIX_BUFOFFSET
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync , &offset_this_run
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync#endif
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync ) || ret;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!stride_this_run && This->conversion_map)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Sanity test */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!ret) ERR("no converted attributes found, old conversion map exists, and no declaration change?\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync HeapFree(GetProcessHeap(), 0, This->conversion_map);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync This->conversion_map = NULL;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync This->stride = 0;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (ret) TRACE("Conversion information changed\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return ret;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstatic inline void fixup_d3dcolor(DWORD *dst_color)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync DWORD src_color = *dst_color;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Color conversion like in drawStridedSlow. watch out for little endianity
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * If we want that stuff to work on big endian machines too we have to consider more things
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync *
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * 0xff000000: Alpha mask
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * 0x00ff0000: Blue mask
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * 0x0000ff00: Green mask
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * 0x000000ff: Red mask
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync *dst_color = 0;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync *dst_color |= (src_color & 0xff00ff00); /* Alpha Green */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync *dst_color |= (src_color & 0x00ff0000) >> 16; /* Red */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync *dst_color |= (src_color & 0x000000ff) << 16; /* Blue */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstatic inline void fixup_transformed_pos(float *p)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* rhw conversion like in position_float4(). */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (p[3] != 1.0f && p[3] != 0.0f)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync float w = 1.0f / p[3];
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync p[0] *= w;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync p[1] *= w;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync p[2] *= w;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync p[3] = w;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync/* Context activation is done by the caller. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncvoid buffer_get_memory(struct wined3d_buffer *buffer, const struct wined3d_gl_info *gl_info,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_bo_address *data)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync data->buffer_object = buffer->buffer_object;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!buffer->buffer_object)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if ((buffer->flags & WINED3D_BUFFER_CREATEBO) && !buffer->resource.map_count)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync buffer_create_buffer_object(buffer, gl_info);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync buffer->flags &= ~WINED3D_BUFFER_CREATEBO;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (buffer->buffer_object)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync data->buffer_object = buffer->buffer_object;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync data->addr = NULL;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync data->addr = buffer->resource.allocatedMemory;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync else
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync data->addr = NULL;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncULONG CDECL wined3d_buffer_incref(struct wined3d_buffer *buffer)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync ULONG refcount = InterlockedIncrement(&buffer->resource.ref);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("%p increasing refcount to %u.\n", buffer, refcount);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return refcount;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync/* Context activation is done by the caller. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncBYTE *buffer_get_sysmem(struct wined3d_buffer *This, const struct wined3d_gl_info *gl_info)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* AllocatedMemory exists if the buffer is double buffered or has no buffer object at all */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if(This->resource.allocatedMemory) return This->resource.allocatedMemory;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync This->resource.heapMemory = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, This->resource.size + RESOURCE_ALIGNMENT);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync This->resource.allocatedMemory = (BYTE *)(((ULONG_PTR)This->resource.heapMemory + (RESOURCE_ALIGNMENT - 1)) & ~(RESOURCE_ALIGNMENT - 1));
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (This->buffer_type_hint == GL_ELEMENT_ARRAY_BUFFER_ARB)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device_invalidate_state(This->resource.device, STATE_INDEXBUFFER);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync GL_EXTCALL(glBindBufferARB(This->buffer_type_hint, This->buffer_object));
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync GL_EXTCALL(glGetBufferSubDataARB(This->buffer_type_hint, 0, This->resource.size, This->resource.allocatedMemory));
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync This->flags |= WINED3D_BUFFER_DOUBLEBUFFER;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return This->resource.allocatedMemory;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync/* Do not call while under the GL lock. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstatic void buffer_unload(struct wined3d_resource *resource)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_buffer *buffer = buffer_from_resource(resource);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("buffer %p.\n", buffer);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (buffer->buffer_object)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_device *device = resource->device;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_context *context;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync context = context_acquire(device, NULL);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Download the buffer, but don't permanently enable double buffering */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!(buffer->flags & WINED3D_BUFFER_DOUBLEBUFFER))
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync buffer_get_sysmem(buffer, context->gl_info);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync buffer->flags &= ~WINED3D_BUFFER_DOUBLEBUFFER;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync delete_gl_buffer(buffer, context->gl_info);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync buffer->flags |= WINED3D_BUFFER_CREATEBO; /* Recreate the buffer object next load */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync buffer_clear_dirty_areas(buffer);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync context_release(context);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync HeapFree(GetProcessHeap(), 0, buffer->conversion_map);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync buffer->conversion_map = NULL;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync buffer->stride = 0;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync buffer->conversion_stride = 0;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync buffer->flags &= ~WINED3D_BUFFER_HASDESC;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync resource_unload(resource);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync/* Do not call while under the GL lock. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncULONG CDECL wined3d_buffer_decref(struct wined3d_buffer *buffer)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync ULONG refcount = InterlockedDecrement(&buffer->resource.ref);
76f3927069cc452e77bf72f32d9175c0256ed3b3vboxsync struct wined3d_context *context;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("%p decreasing refcount to %u.\n", buffer, refcount);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!refcount)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
76f3927069cc452e77bf72f32d9175c0256ed3b3vboxsync if (buffer->buffer_object)
76f3927069cc452e77bf72f32d9175c0256ed3b3vboxsync {
76f3927069cc452e77bf72f32d9175c0256ed3b3vboxsync context = context_acquire(buffer->resource.device, NULL);
76f3927069cc452e77bf72f32d9175c0256ed3b3vboxsync delete_gl_buffer(buffer, context->gl_info);
76f3927069cc452e77bf72f32d9175c0256ed3b3vboxsync context_release(context);
76f3927069cc452e77bf72f32d9175c0256ed3b3vboxsync
76f3927069cc452e77bf72f32d9175c0256ed3b3vboxsync HeapFree(GetProcessHeap(), 0, buffer->conversion_map);
76f3927069cc452e77bf72f32d9175c0256ed3b3vboxsync }
76f3927069cc452e77bf72f32d9175c0256ed3b3vboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync resource_cleanup(&buffer->resource);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync buffer->resource.parent_ops->wined3d_object_destroyed(buffer->resource.parent);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync HeapFree(GetProcessHeap(), 0, buffer->maps);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync HeapFree(GetProcessHeap(), 0, buffer);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return refcount;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncvoid * CDECL wined3d_buffer_get_parent(const struct wined3d_buffer *buffer)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("buffer %p.\n", buffer);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return buffer->resource.parent;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncDWORD CDECL wined3d_buffer_set_priority(struct wined3d_buffer *buffer, DWORD priority)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return resource_set_priority(&buffer->resource, priority);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncDWORD CDECL wined3d_buffer_get_priority(const struct wined3d_buffer *buffer)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return resource_get_priority(&buffer->resource);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync/* The caller provides a context and binds the buffer */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstatic void buffer_sync_apple(struct wined3d_buffer *This, DWORD flags, const struct wined3d_gl_info *gl_info)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync enum wined3d_event_query_result ret;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* No fencing needs to be done if the app promises not to overwrite
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * existing data. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (flags & WINED3D_MAP_NOOVERWRITE)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (flags & WINED3D_MAP_DISCARD)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync GL_EXTCALL(glBufferDataARB(This->buffer_type_hint, This->resource.size, NULL, This->buffer_object_usage));
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync checkGLcall("glBufferDataARB\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if(!This->query)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("Creating event query for buffer %p\n", This);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!wined3d_event_query_supported(gl_info))
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync FIXME("Event queries not supported, dropping async buffer locks.\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync goto drop_query;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync This->query = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*This->query));
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!This->query)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync ERR("Failed to allocate event query memory, dropping async buffer locks.\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync goto drop_query;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Since we don't know about old draws a glFinish is needed once */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync gl_info->gl_ops.gl.p_glFinish();
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("Synchronizing buffer %p\n", This);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync ret = wined3d_event_query_finish(This->query, This->resource.device);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync switch(ret)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case WINED3D_EVENT_QUERY_NOT_STARTED:
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case WINED3D_EVENT_QUERY_OK:
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* All done */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case WINED3D_EVENT_QUERY_WRONG_THREAD:
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync WARN("Cannot synchronize buffer lock due to a thread conflict\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync goto drop_query;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync default:
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync ERR("wined3d_event_query_finish returned %u, dropping async buffer locks\n", ret);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync goto drop_query;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncdrop_query:
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if(This->query)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_event_query_destroy(This->query);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync This->query = NULL;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync gl_info->gl_ops.gl.p_glFinish();
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync GL_EXTCALL(glBufferParameteriAPPLE(This->buffer_type_hint, GL_BUFFER_SERIALIZED_MODIFY_APPLE, GL_TRUE));
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync checkGLcall("glBufferParameteriAPPLE(This->buffer_type_hint, GL_BUFFER_SERIALIZED_MODIFY_APPLE, GL_TRUE)");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync This->flags &= ~WINED3D_BUFFER_APPLESYNC;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync/* The caller provides a GL context */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstatic void buffer_direct_upload(struct wined3d_buffer *This, const struct wined3d_gl_info *gl_info, DWORD flags)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync BYTE *map;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync UINT start = 0, len = 0;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* This potentially invalidates the element array buffer binding, but the
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * caller always takes care of this. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync GL_EXTCALL(glBindBufferARB(This->buffer_type_hint, This->buffer_object));
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync checkGLcall("glBindBufferARB");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (gl_info->supported[ARB_MAP_BUFFER_RANGE])
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync GLbitfield mapflags;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync mapflags = GL_MAP_WRITE_BIT | GL_MAP_FLUSH_EXPLICIT_BIT;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (flags & WINED3D_BUFFER_DISCARD)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync mapflags |= GL_MAP_INVALIDATE_BUFFER_BIT;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (flags & WINED3D_BUFFER_NOSYNC)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync mapflags |= GL_MAP_UNSYNCHRONIZED_BIT;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync map = GL_EXTCALL(glMapBufferRange(This->buffer_type_hint, 0,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync This->resource.size, mapflags));
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync checkGLcall("glMapBufferRange");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync else
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (This->flags & WINED3D_BUFFER_APPLESYNC)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync DWORD syncflags = 0;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (flags & WINED3D_BUFFER_DISCARD)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync syncflags |= WINED3D_MAP_DISCARD;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (flags & WINED3D_BUFFER_NOSYNC)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync syncflags |= WINED3D_MAP_NOOVERWRITE;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync buffer_sync_apple(This, syncflags, gl_info);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync map = GL_EXTCALL(glMapBufferARB(This->buffer_type_hint, GL_WRITE_ONLY_ARB));
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync checkGLcall("glMapBufferARB");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!map)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync ERR("Failed to map opengl buffer\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync while (This->modified_areas)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync This->modified_areas--;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync start = This->maps[This->modified_areas].offset;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync len = This->maps[This->modified_areas].size;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync memcpy(map + start, This->resource.allocatedMemory + start, len);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (gl_info->supported[ARB_MAP_BUFFER_RANGE])
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync GL_EXTCALL(glFlushMappedBufferRange(This->buffer_type_hint, start, len));
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync checkGLcall("glFlushMappedBufferRange");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync else if (This->flags & WINED3D_BUFFER_FLUSH)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync GL_EXTCALL(glFlushMappedBufferRangeAPPLE(This->buffer_type_hint, start, len));
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync checkGLcall("glFlushMappedBufferRangeAPPLE");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync GL_EXTCALL(glUnmapBufferARB(This->buffer_type_hint));
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync checkGLcall("glUnmapBufferARB");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync#ifdef VBOX_WITH_WINE_FIX_BUFOFFSET
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstatic UINT wined3d_buffer_stream_offset_left(UINT x, UINT offset, UINT stride)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync UINT off = ((UINT)(RT_ABS((INT)(x - offset))) % stride);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!off)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return x;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (x > offset)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return x - off;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* x < offset */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return x - stride + off;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstatic UINT wined3d_buffer_stream_offset_right(UINT x, UINT offset, UINT stride)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync UINT left = wined3d_buffer_stream_offset_left(x, offset, stride);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (left == x)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return x;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return left + stride;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync#endif
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync/* Do not call while under the GL lock. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncvoid CDECL wined3d_buffer_preload(struct wined3d_buffer *buffer)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync DWORD flags = buffer->flags & (WINED3D_BUFFER_NOSYNC | WINED3D_BUFFER_DISCARD);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_device *device = buffer->resource.device;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync UINT start = 0, end = 0, len = 0, vertices;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync const struct wined3d_gl_info *gl_info;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_context *context;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync BOOL decl_changed = FALSE;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync unsigned int i, j;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync BYTE *data;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync#ifdef VBOX_WITH_WINE_FIX_BUFOFFSET
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync BYTE *cur_ptr;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync UINT conv_start, conv_end;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync#endif
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("buffer %p.\n", buffer);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (buffer->resource.map_count)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync WARN("Buffer is mapped, skipping preload.\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync buffer->flags &= ~(WINED3D_BUFFER_NOSYNC | WINED3D_BUFFER_DISCARD);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!buffer->buffer_object)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* TODO: Make converting independent from VBOs */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (buffer->flags & WINED3D_BUFFER_CREATEBO)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync context = context_acquire(device, NULL);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync buffer_create_buffer_object(buffer, context->gl_info);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync context_release(context);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync buffer->flags &= ~WINED3D_BUFFER_CREATEBO;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync else
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Not doing any conversion */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Reading the declaration makes only sense if the stateblock is finalized and the buffer bound to a stream */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (device->isInDraw && buffer->resource.bind_count > 0)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync decl_changed = buffer_find_decl(buffer);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync buffer->flags |= WINED3D_BUFFER_HASDESC;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!decl_changed && !(buffer->flags & WINED3D_BUFFER_HASDESC && buffer_is_dirty(buffer)))
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync ++buffer->draw_count;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (buffer->draw_count > VB_RESETDECLCHANGE)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync buffer->decl_change_count = 0;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (buffer->draw_count > VB_RESETFULLCONVS)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync buffer->full_conversion_count = 0;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* If applications change the declaration over and over, reconverting all the time is a huge
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * performance hit. So count the declaration changes and release the VBO if there are too many
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * of them (and thus stop converting)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (decl_changed)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync ++buffer->decl_change_count;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync buffer->draw_count = 0;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (buffer->decl_change_count > VB_MAXDECLCHANGES
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync || (buffer->conversion_map && (buffer->resource.usage & WINED3DUSAGE_DYNAMIC)))
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync FIXME("Too many declaration changes or converting dynamic buffer, stopping converting\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync buffer_unload(&buffer->resource);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync buffer->flags &= ~WINED3D_BUFFER_CREATEBO;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* The stream source state handler might have read the memory of
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * the vertex buffer already and got the memory in the vbo which
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * is not valid any longer. Dirtify the stream source to force a
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * reload. This happens only once per changed vertexbuffer and
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * should occur rather rarely. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device_invalidate_state(device, STATE_STREAMSRC);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* The declaration changed, reload the whole buffer */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync WARN("Reloading buffer because of decl change\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync buffer_clear_dirty_areas(buffer);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!buffer_add_dirty_area(buffer, 0, 0))
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync ERR("buffer_add_dirty_area failed, this is not expected\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Avoid unfenced updates, we might overwrite more areas of the buffer than the application
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * cleared for unsynchronized updates
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync flags = 0;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync else
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* However, it is perfectly fine to change the declaration every now and then. We don't want a game that
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * changes it every minute drop the VBO after VB_MAX_DECL_CHANGES minutes. So count draws without
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * decl changes and reset the decl change count after a specific number of them
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (buffer->conversion_map && buffer_is_fully_dirty(buffer))
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync ++buffer->full_conversion_count;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (buffer->full_conversion_count > VB_MAXFULLCONVERSIONS)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync FIXME("Too many full buffer conversions, stopping converting.\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync buffer_unload(&buffer->resource);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync buffer->flags &= ~WINED3D_BUFFER_CREATEBO;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (buffer->resource.bind_count)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device_invalidate_state(device, STATE_STREAMSRC);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync else
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync ++buffer->draw_count;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (buffer->draw_count > VB_RESETDECLCHANGE)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync buffer->decl_change_count = 0;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (buffer->draw_count > VB_RESETFULLCONVS)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync buffer->full_conversion_count = 0;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (buffer->buffer_type_hint == GL_ELEMENT_ARRAY_BUFFER_ARB)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device_invalidate_state(device, STATE_INDEXBUFFER);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!buffer->conversion_map)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* That means that there is nothing to fixup. Just upload from
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * buffer->resource.allocatedMemory directly into the vbo. Do not
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * free the system memory copy because drawPrimitive may need it if
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * the stride is 0, for instancing emulation, vertex blending
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * emulation or shader emulation. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("No conversion needed.\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Nothing to do because we locked directly into the vbo */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!(buffer->flags & WINED3D_BUFFER_DOUBLEBUFFER))
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync context = context_acquire(device, NULL);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync buffer_direct_upload(buffer, context->gl_info, flags);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync context_release(context);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync context = context_acquire(device, NULL);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync gl_info = context->gl_info;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if(!(buffer->flags & WINED3D_BUFFER_DOUBLEBUFFER))
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync buffer_get_sysmem(buffer, gl_info);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Now for each vertex in the buffer that needs conversion */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync vertices = buffer->resource.size / buffer->stride;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync data = HeapAlloc(GetProcessHeap(), 0, buffer->resource.size);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync while(buffer->modified_areas)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync buffer->modified_areas--;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync start = buffer->maps[buffer->modified_areas].offset;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync len = buffer->maps[buffer->modified_areas].size;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync end = start + len;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync#ifdef VBOX_WITH_WINE_FIX_BUFOFFSET
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (buffer->offset > UINT32_MAX)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync ERR("negative offset, unexpected!");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync conv_start = wined3d_buffer_stream_offset_left(start, buffer->offset, buffer->stride);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (conv_start <= start)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync start = conv_start;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync else
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* <- < 0, add stride */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync conv_start += buffer->stride;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync Assert(conv_start < UINT32_MAX/3);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync conv_end = wined3d_buffer_stream_offset_right(end, buffer->offset, buffer->stride);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (conv_end > end)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (conv_end <= buffer->resource.size)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync end = conv_end;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync else
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync conv_end -= buffer->stride;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync else if (conv_end < end)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync ERR("unexpected!");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync else
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync end = conv_end;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync#endif
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync memcpy(data + start, buffer->resource.allocatedMemory + start, end - start);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync#ifdef VBOX_WITH_WINE_FIX_BUFOFFSET
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync for (cur_ptr = data + conv_start; cur_ptr < data + conv_end; cur_ptr += buffer->stride)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync#else
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync for (i = start / buffer->stride; i < min((end / buffer->stride) + 1, vertices); ++i)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync#endif
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync for (j = 0; j < buffer->stride; ++j)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync switch (buffer->conversion_map[j])
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case CONV_NONE:
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Done already */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync j += 3;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync break;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case CONV_D3DCOLOR:
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync#ifdef VBOX_WITH_WINE_FIX_BUFOFFSET
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync fixup_d3dcolor((DWORD *) (cur_ptr + j));
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync#else
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync fixup_d3dcolor((DWORD *) (data + i * buffer->stride + j));
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync#endif
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync j += 3;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync break;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case CONV_POSITIONT:
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync#ifdef VBOX_WITH_WINE_FIX_BUFOFFSET
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync fixup_transformed_pos((float *) (cur_ptr + j));
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync#else
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync fixup_transformed_pos((float *) (data + i * buffer->stride + j));
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync#endif
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync j += 15;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync break;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync default:
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync FIXME("Unimplemented conversion %d in shifted conversion\n", buffer->conversion_map[j]);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync GL_EXTCALL(glBindBufferARB(buffer->buffer_type_hint, buffer->buffer_object));
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync checkGLcall("glBindBufferARB");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync GL_EXTCALL(glBufferSubDataARB(buffer->buffer_type_hint, start, len, data + start));
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync checkGLcall("glBufferSubDataARB");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync HeapFree(GetProcessHeap(), 0, data);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync context_release(context);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstatic DWORD buffer_sanitize_flags(const struct wined3d_buffer *buffer, DWORD flags)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Not all flags make sense together, but Windows never returns an error.
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * Catch the cases that could cause issues. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (flags & WINED3D_MAP_READONLY)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (flags & WINED3D_MAP_DISCARD)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync WARN("WINED3D_MAP_READONLY combined with WINED3D_MAP_DISCARD, ignoring flags.\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return 0;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (flags & WINED3D_MAP_NOOVERWRITE)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync WARN("WINED3D_MAP_READONLY combined with WINED3D_MAP_NOOVERWRITE, ignoring flags.\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return 0;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync else if ((flags & (WINED3D_MAP_DISCARD | WINED3D_MAP_NOOVERWRITE))
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync == (WINED3D_MAP_DISCARD | WINED3D_MAP_NOOVERWRITE))
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync WARN("WINED3D_MAP_DISCARD and WINED3D_MAP_NOOVERWRITE used together, ignoring.\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return 0;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync else if (flags & (WINED3D_MAP_DISCARD | WINED3D_MAP_NOOVERWRITE)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync && !(buffer->resource.usage & WINED3DUSAGE_DYNAMIC))
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync WARN("DISCARD or NOOVERWRITE map on non-dynamic buffer, ignoring.\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return 0;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return flags;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstatic GLbitfield buffer_gl_map_flags(DWORD d3d_flags)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync GLbitfield ret = 0;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!(d3d_flags & WINED3D_MAP_READONLY))
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync ret |= GL_MAP_WRITE_BIT | GL_MAP_FLUSH_EXPLICIT_BIT;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!(d3d_flags & (WINED3D_MAP_DISCARD | WINED3D_MAP_NOOVERWRITE)))
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync ret |= GL_MAP_READ_BIT;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (d3d_flags & WINED3D_MAP_DISCARD)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync ret |= GL_MAP_INVALIDATE_BUFFER_BIT;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (d3d_flags & WINED3D_MAP_NOOVERWRITE)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync ret |= GL_MAP_UNSYNCHRONIZED_BIT;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return ret;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstruct wined3d_resource * CDECL wined3d_buffer_get_resource(struct wined3d_buffer *buffer)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("buffer %p.\n", buffer);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return &buffer->resource;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncHRESULT CDECL wined3d_buffer_map(struct wined3d_buffer *buffer, UINT offset, UINT size, BYTE **data, DWORD flags)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync BOOL dirty = buffer_is_dirty(buffer);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync LONG count;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("buffer %p, offset %u, size %u, data %p, flags %#x\n", buffer, offset, size, data, flags);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync flags = buffer_sanitize_flags(buffer, flags);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (flags & WINED3D_MAP_DISCARD)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* DISCARD invalidates the entire buffer, regardless of the specified
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * offset and size. Some applications also depend on the entire buffer
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * being uploaded in that case. Two such applications are Port Royale
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * and Darkstar One. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!buffer_add_dirty_area(buffer, 0, 0))
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return E_OUTOFMEMORY;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync else if (!(flags & WINED3D_MAP_READONLY))
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!buffer_add_dirty_area(buffer, offset, size))
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return E_OUTOFMEMORY;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync count = ++buffer->resource.map_count;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (buffer->buffer_object)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!(buffer->flags & WINED3D_BUFFER_DOUBLEBUFFER))
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (count == 1)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_device *device = buffer->resource.device;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_context *context;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync const struct wined3d_gl_info *gl_info;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync context = context_acquire(device, NULL);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync gl_info = context->gl_info;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (buffer->buffer_type_hint == GL_ELEMENT_ARRAY_BUFFER_ARB)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync context_invalidate_state(context, STATE_INDEXBUFFER);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync GL_EXTCALL(glBindBufferARB(buffer->buffer_type_hint, buffer->buffer_object));
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (gl_info->supported[ARB_MAP_BUFFER_RANGE])
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync GLbitfield mapflags = buffer_gl_map_flags(flags);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync buffer->resource.allocatedMemory = GL_EXTCALL(glMapBufferRange(buffer->buffer_type_hint,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync 0, buffer->resource.size, mapflags));
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync checkGLcall("glMapBufferRange");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync else
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (buffer->flags & WINED3D_BUFFER_APPLESYNC)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync buffer_sync_apple(buffer, flags, gl_info);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync buffer->resource.allocatedMemory = GL_EXTCALL(glMapBufferARB(buffer->buffer_type_hint,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync GL_READ_WRITE_ARB));
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync checkGLcall("glMapBufferARB");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (((DWORD_PTR)buffer->resource.allocatedMemory) & (RESOURCE_ALIGNMENT - 1))
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync WARN("Pointer %p is not %u byte aligned.\n", buffer->resource.allocatedMemory, RESOURCE_ALIGNMENT);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync GL_EXTCALL(glUnmapBufferARB(buffer->buffer_type_hint));
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync checkGLcall("glUnmapBufferARB");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync buffer->resource.allocatedMemory = NULL;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (buffer->resource.usage & WINED3DUSAGE_DYNAMIC)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* The extra copy is more expensive than not using VBOs at
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * all on the Nvidia Linux driver, which is the only driver
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * that returns unaligned pointers
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("Dynamic buffer, dropping VBO\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync buffer_unload(&buffer->resource);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync buffer->flags &= ~WINED3D_BUFFER_CREATEBO;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (buffer->resource.bind_count)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device_invalidate_state(device, STATE_STREAMSRC);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync else
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("Falling back to doublebuffered operation\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync buffer_get_sysmem(buffer, gl_info);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("New pointer is %p.\n", buffer->resource.allocatedMemory);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync context_release(context);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync else
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (dirty)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (buffer->flags & WINED3D_BUFFER_NOSYNC && !(flags & WINED3D_MAP_NOOVERWRITE))
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync buffer->flags &= ~WINED3D_BUFFER_NOSYNC;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync else if(flags & WINED3D_MAP_NOOVERWRITE)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync buffer->flags |= WINED3D_BUFFER_NOSYNC;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (flags & WINED3D_MAP_DISCARD)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync buffer->flags |= WINED3D_BUFFER_DISCARD;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync *data = buffer->resource.allocatedMemory + offset;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("Returning memory at %p (base %p, offset %u).\n", *data, buffer->resource.allocatedMemory, offset);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* TODO: check Flags compatibility with buffer->currentDesc.Usage (see MSDN) */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return WINED3D_OK;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncvoid CDECL wined3d_buffer_unmap(struct wined3d_buffer *buffer)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync ULONG i;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("buffer %p.\n", buffer);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* In the case that the number of Unmap calls > the
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * number of Map calls, d3d returns always D3D_OK.
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * This is also needed to prevent Map from returning garbage on
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * the next call (this will happen if the lock_count is < 0). */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!buffer->resource.map_count)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync WARN("Unmap called without a previous map call.\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (--buffer->resource.map_count)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Delay loading the buffer until everything is unlocked */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("Ignoring unmap.\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!(buffer->flags & WINED3D_BUFFER_DOUBLEBUFFER) && buffer->buffer_object)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_device *device = buffer->resource.device;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync const struct wined3d_gl_info *gl_info;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_context *context;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync context = context_acquire(device, NULL);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync gl_info = context->gl_info;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (buffer->buffer_type_hint == GL_ELEMENT_ARRAY_BUFFER_ARB)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync context_invalidate_state(context, STATE_INDEXBUFFER);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync GL_EXTCALL(glBindBufferARB(buffer->buffer_type_hint, buffer->buffer_object));
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (gl_info->supported[ARB_MAP_BUFFER_RANGE])
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync for (i = 0; i < buffer->modified_areas; ++i)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync GL_EXTCALL(glFlushMappedBufferRange(buffer->buffer_type_hint,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync buffer->maps[i].offset, buffer->maps[i].size));
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync checkGLcall("glFlushMappedBufferRange");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync else if (buffer->flags & WINED3D_BUFFER_FLUSH)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync for (i = 0; i < buffer->modified_areas; ++i)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync GL_EXTCALL(glFlushMappedBufferRangeAPPLE(buffer->buffer_type_hint,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync buffer->maps[i].offset, buffer->maps[i].size));
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync checkGLcall("glFlushMappedBufferRangeAPPLE");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync GL_EXTCALL(glUnmapBufferARB(buffer->buffer_type_hint));
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (wined3d_settings.strict_draw_ordering)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync gl_info->gl_ops.gl.p_glFlush(); /* Flush to ensure ordering across contexts. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync context_release(context);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync buffer->resource.allocatedMemory = NULL;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync buffer_clear_dirty_areas(buffer);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync else if (buffer->flags & WINED3D_BUFFER_HASDESC)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_buffer_preload(buffer);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstatic const struct wined3d_resource_ops buffer_resource_ops =
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync buffer_unload,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync};
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstatic HRESULT buffer_init(struct wined3d_buffer *buffer, struct wined3d_device *device,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync UINT size, DWORD usage, enum wined3d_format_id format_id, enum wined3d_pool pool, GLenum bind_hint,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync const char *data, void *parent, const struct wined3d_parent_ops *parent_ops)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync const struct wined3d_gl_info *gl_info = &device->adapter->gl_info;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync const struct wined3d_format *format = wined3d_get_format(gl_info, format_id);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync HRESULT hr;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync BOOL dynamic_buffer_ok;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!size)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync WARN("Size 0 requested, returning WINED3DERR_INVALIDCALL\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return WINED3DERR_INVALIDCALL;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync hr = resource_init(&buffer->resource, device, WINED3D_RTYPE_BUFFER, format,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync WINED3D_MULTISAMPLE_NONE, 0, usage, pool, size, 1, 1, size,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync parent, parent_ops, &buffer_resource_ops
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync#ifdef VBOX_WITH_WDDM
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync , NULL, NULL /* <- no need this info here so far */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync#endif
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync );
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (FAILED(hr))
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync WARN("Failed to initialize resource, hr %#x\n", hr);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return hr;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync buffer->buffer_type_hint = bind_hint;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("size %#x, usage %#x, format %s, memory @ %p, iface @ %p.\n", buffer->resource.size, buffer->resource.usage,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync debug_d3dformat(buffer->resource.format->id), buffer->resource.allocatedMemory, buffer);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (device->create_parms.flags & WINED3DCREATE_SOFTWARE_VERTEXPROCESSING)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* SWvp always returns the same pointer in buffer maps and retains data in DISCARD maps.
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * Keep a system memory copy of the buffer to provide the same behavior to the application.
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * Still use a VBO to support OpenGL 3 core contexts. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("Using doublebuffer mode because of software vertex processing\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync buffer->flags |= WINED3D_BUFFER_DOUBLEBUFFER;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync dynamic_buffer_ok = gl_info->supported[APPLE_FLUSH_BUFFER_RANGE] || gl_info->supported[ARB_MAP_BUFFER_RANGE];
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Observations show that drawStridedSlow is faster on dynamic VBs than converting +
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * drawStridedFast (half-life 2 and others).
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync *
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * Basically converting the vertices in the buffer is quite expensive, and observations
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * show that drawStridedSlow is faster than converting + uploading + drawStridedFast.
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * Therefore do not create a VBO for WINED3DUSAGE_DYNAMIC buffers.
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!gl_info->supported[ARB_VERTEX_BUFFER_OBJECT])
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("Not creating a vbo because GL_ARB_vertex_buffer is not supported\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync#ifndef VBOX_WITH_WDDM /* @todo: extend this to VBOX in general */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync else if(buffer->resource.pool == WINED3D_POOL_SYSTEM_MEM)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("Not creating a vbo because the vertex buffer is in system memory\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync else if(!dynamic_buffer_ok && (buffer->resource.usage & WINED3DUSAGE_DYNAMIC))
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("Not creating a vbo because the buffer has dynamic usage and no GL support\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync#endif
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync else
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync buffer->flags |= WINED3D_BUFFER_CREATEBO;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (data)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync BYTE *ptr;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync hr = wined3d_buffer_map(buffer, 0, size, &ptr, 0);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (FAILED(hr))
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync ERR("Failed to map buffer, hr %#x\n", hr);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync buffer_unload(&buffer->resource);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync resource_cleanup(&buffer->resource);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return hr;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync memcpy(ptr, data, size);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_buffer_unmap(buffer);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync buffer->maps = HeapAlloc(GetProcessHeap(), 0, sizeof(*buffer->maps));
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!buffer->maps)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync ERR("Out of memory\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync buffer_unload(&buffer->resource);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync resource_cleanup(&buffer->resource);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return E_OUTOFMEMORY;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync buffer->maps_size = 1;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return WINED3D_OK;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncHRESULT CDECL wined3d_buffer_create(struct wined3d_device *device, struct wined3d_buffer_desc *desc, const void *data,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync void *parent, const struct wined3d_parent_ops *parent_ops, struct wined3d_buffer **buffer)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_buffer *object;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync HRESULT hr;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("device %p, desc %p, data %p, parent %p, buffer %p\n", device, desc, data, parent, buffer);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!object)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return E_OUTOFMEMORY;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync FIXME("Ignoring access flags (pool)\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync hr = buffer_init(object, device, desc->byte_width, desc->usage, WINED3DFMT_UNKNOWN,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync WINED3D_POOL_MANAGED, GL_ARRAY_BUFFER_ARB, data, parent, parent_ops);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (FAILED(hr))
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync WARN("Failed to initialize buffer, hr %#x.\n", hr);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync HeapFree(GetProcessHeap(), 0, object);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return hr;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync object->desc = *desc;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("Created buffer %p.\n", object);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync *buffer = object;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return WINED3D_OK;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncHRESULT CDECL wined3d_buffer_create_vb(struct wined3d_device *device, UINT size, DWORD usage, enum wined3d_pool pool,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync void *parent, const struct wined3d_parent_ops *parent_ops, struct wined3d_buffer **buffer)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_buffer *object;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync HRESULT hr;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("device %p, size %u, usage %#x, pool %#x, parent %p, parent_ops %p, buffer %p.\n",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device, size, usage, pool, parent, parent_ops, buffer);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (pool == WINED3D_POOL_SCRATCH)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* The d3d9 tests shows that this is not allowed. It doesn't make much
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * sense anyway, SCRATCH buffers wouldn't be usable anywhere. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync WARN("Vertex buffer in WINED3D_POOL_SCRATCH requested, returning WINED3DERR_INVALIDCALL.\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync *buffer = NULL;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return WINED3DERR_INVALIDCALL;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!object)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync *buffer = NULL;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return WINED3DERR_OUTOFVIDEOMEMORY;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync hr = buffer_init(object, device, size, usage, WINED3DFMT_VERTEXDATA,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync pool, GL_ARRAY_BUFFER_ARB, NULL, parent, parent_ops);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (FAILED(hr))
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync WARN("Failed to initialize buffer, hr %#x.\n", hr);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync HeapFree(GetProcessHeap(), 0, object);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return hr;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("Created buffer %p.\n", object);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync *buffer = object;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return WINED3D_OK;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncHRESULT CDECL wined3d_buffer_create_ib(struct wined3d_device *device, UINT size, DWORD usage, enum wined3d_pool pool,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync void *parent, const struct wined3d_parent_ops *parent_ops, struct wined3d_buffer **buffer)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_buffer *object;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync HRESULT hr;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("device %p, size %u, usage %#x, pool %#x, parent %p, parent_ops %p, buffer %p.\n",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device, size, usage, pool, parent, parent_ops, buffer);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!object)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync *buffer = NULL;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return WINED3DERR_OUTOFVIDEOMEMORY;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync hr = buffer_init(object, device, size, usage | WINED3DUSAGE_STATICDECL,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync WINED3DFMT_UNKNOWN, pool, GL_ELEMENT_ARRAY_BUFFER_ARB, NULL,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync parent, parent_ops);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (FAILED(hr))
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync WARN("Failed to initialize buffer, hr %#x\n", hr);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync HeapFree(GetProcessHeap(), 0, object);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return hr;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("Created buffer %p.\n", object);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync *buffer = object;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return WINED3D_OK;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}