2005-01-17 14:44:57 +01:00
|
|
|
/*
|
|
|
|
* Copyright 2002-2005 Jason Edmeades
|
2005-03-29 21:01:00 +02:00
|
|
|
* Copyright 2002-2005 Raphael Junqueira
|
2005-07-13 16:15:54 +02:00
|
|
|
* Copyright 2005 Oliver Stieber
|
2011-04-14 22:41:47 +02:00
|
|
|
* Copyright 2009-2011 Henri Verbeet for CodeWeavers
|
2013-08-22 14:57:54 +02:00
|
|
|
* Copyright 2013 Stefan Dösinger for CodeWeavers
|
2005-01-17 14:44:57 +01:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2005-01-17 14:44:57 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
2012-06-01 16:56:21 +02:00
|
|
|
#include "wine/port.h"
|
2005-01-17 14:44:57 +01:00
|
|
|
#include "wined3d_private.h"
|
|
|
|
|
2008-09-17 17:51:44 +02:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(d3d_surface);
|
2013-08-26 02:01:29 +02:00
|
|
|
WINE_DECLARE_DEBUG_CHANNEL(d3d_perf);
|
2010-05-24 09:56:36 +02:00
|
|
|
|
2009-06-26 10:07:12 +02:00
|
|
|
/* Context activation is done by the caller. */
|
2013-08-26 02:01:29 +02:00
|
|
|
static void volume_bind_and_dirtify(const struct wined3d_volume *volume,
|
|
|
|
struct wined3d_context *context, BOOL srgb)
|
2011-01-18 17:55:20 +01:00
|
|
|
{
|
2011-03-18 19:11:00 +01:00
|
|
|
struct wined3d_texture *container = volume->container;
|
2009-08-17 09:39:07 +02:00
|
|
|
DWORD active_sampler;
|
2008-09-17 17:50:40 +02:00
|
|
|
|
|
|
|
/* We don't need a specific texture unit, but after binding the texture the current unit is dirty.
|
|
|
|
* Read the unit back instead of switching to 0, this avoids messing around with the state manager's
|
|
|
|
* gl states. The current texture unit should always be a valid one.
|
|
|
|
*
|
|
|
|
* To be more specific, this is tricky because we can implicitly be called
|
|
|
|
* from sampler() in state.c. This means we can't touch anything other than
|
|
|
|
* whatever happens to be the currently active texture, or we would risk
|
2011-07-26 23:01:26 +02:00
|
|
|
* marking already applied sampler states dirty again. */
|
2013-09-16 12:43:18 +02:00
|
|
|
active_sampler = context->rev_tex_unit_map[context->active_texture];
|
2008-09-17 17:50:40 +02:00
|
|
|
|
2009-08-17 09:39:07 +02:00
|
|
|
if (active_sampler != WINED3D_UNMAPPED_STAGE)
|
2013-09-16 12:43:18 +02:00
|
|
|
context_invalidate_state(context, STATE_SAMPLER(active_sampler));
|
2008-09-17 17:50:40 +02:00
|
|
|
|
2013-08-26 02:01:29 +02:00
|
|
|
container->texture_ops->texture_bind(container, context, srgb);
|
2008-09-17 17:50:40 +02:00
|
|
|
}
|
|
|
|
|
2011-04-14 22:41:48 +02:00
|
|
|
void volume_set_container(struct wined3d_volume *volume, struct wined3d_texture *container)
|
2010-08-16 20:00:22 +02:00
|
|
|
{
|
|
|
|
TRACE("volume %p, container %p.\n", volume, container);
|
|
|
|
|
|
|
|
volume->container = container;
|
|
|
|
}
|
|
|
|
|
2013-09-23 13:29:16 +02:00
|
|
|
static BOOL volume_prepare_system_memory(struct wined3d_volume *volume)
|
|
|
|
{
|
|
|
|
if (volume->resource.heap_memory)
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
if (!wined3d_resource_allocate_sysmem(&volume->resource))
|
|
|
|
{
|
|
|
|
ERR("Failed to allocate system memory.\n");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2011-01-20 19:52:01 +01:00
|
|
|
/* Context activation is done by the caller. */
|
2013-09-23 13:29:16 +02:00
|
|
|
static void wined3d_volume_allocate_texture(struct wined3d_volume *volume,
|
2013-08-26 02:01:29 +02:00
|
|
|
const struct wined3d_context *context, BOOL srgb)
|
2013-08-22 14:57:55 +02:00
|
|
|
{
|
|
|
|
const struct wined3d_gl_info *gl_info = context->gl_info;
|
|
|
|
const struct wined3d_format *format = volume->resource.format;
|
2013-09-23 13:29:16 +02:00
|
|
|
void *mem = NULL;
|
|
|
|
|
|
|
|
if (gl_info->supported[APPLE_CLIENT_STORAGE] && !format->convert
|
|
|
|
&& volume_prepare_system_memory(volume))
|
|
|
|
{
|
|
|
|
TRACE("Enabling GL_UNPACK_CLIENT_STORAGE_APPLE for volume %p\n", volume);
|
|
|
|
gl_info->gl_ops.gl.p_glPixelStorei(GL_UNPACK_CLIENT_STORAGE_APPLE, GL_TRUE);
|
|
|
|
checkGLcall("glPixelStorei(GL_UNPACK_CLIENT_STORAGE_APPLE, GL_TRUE)");
|
|
|
|
mem = volume->resource.heap_memory;
|
|
|
|
volume->flags |= WINED3D_VFLAG_CLIENT_STORAGE;
|
|
|
|
}
|
2013-08-22 14:57:55 +02:00
|
|
|
|
2013-08-26 02:01:29 +02:00
|
|
|
GL_EXTCALL(glTexImage3DEXT(GL_TEXTURE_3D, volume->texture_level,
|
|
|
|
srgb ? format->glGammaInternal : format->glInternal,
|
2013-08-22 14:57:55 +02:00
|
|
|
volume->resource.width, volume->resource.height, volume->resource.depth,
|
2013-09-23 13:29:16 +02:00
|
|
|
0, format->glFormat, format->glType, mem));
|
2013-08-22 14:57:55 +02:00
|
|
|
checkGLcall("glTexImage3D");
|
2013-09-23 13:29:16 +02:00
|
|
|
|
|
|
|
if (mem)
|
|
|
|
{
|
|
|
|
gl_info->gl_ops.gl.p_glPixelStorei(GL_UNPACK_CLIENT_STORAGE_APPLE, GL_FALSE);
|
|
|
|
checkGLcall("glPixelStorei(GL_UNPACK_CLIENT_STORAGE_APPLE, GL_FALSE)");
|
|
|
|
}
|
2013-08-22 14:57:55 +02:00
|
|
|
}
|
|
|
|
|
2013-09-18 12:24:56 +02:00
|
|
|
static void wined3d_volume_get_pitch(const struct wined3d_volume *volume, UINT *row_pitch,
|
|
|
|
UINT *slice_pitch)
|
|
|
|
{
|
|
|
|
const struct wined3d_format *format = volume->resource.format;
|
|
|
|
|
|
|
|
if (format->flags & WINED3DFMT_FLAG_BLOCKS)
|
|
|
|
{
|
|
|
|
/* Since compressed formats are block based, pitch means the amount of
|
|
|
|
* bytes to the next row of block rather than the next row of pixels. */
|
|
|
|
UINT row_block_count = (volume->resource.width + format->block_width - 1) / format->block_width;
|
|
|
|
UINT slice_block_count = (volume->resource.height + format->block_height - 1) / format->block_height;
|
|
|
|
*row_pitch = row_block_count * format->block_byte_count;
|
|
|
|
*slice_pitch = *row_pitch * slice_block_count;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
unsigned char alignment = volume->resource.device->surface_alignment;
|
|
|
|
*row_pitch = format->byte_count * volume->resource.width; /* Bytes / row */
|
|
|
|
*row_pitch = (*row_pitch + alignment - 1) & ~(alignment - 1);
|
|
|
|
*slice_pitch = *row_pitch * volume->resource.height;
|
|
|
|
}
|
|
|
|
|
|
|
|
TRACE("Returning row pitch %u, slice pitch %u.\n", *row_pitch, *slice_pitch);
|
|
|
|
}
|
|
|
|
|
2013-08-22 14:57:55 +02:00
|
|
|
/* Context activation is done by the caller. */
|
2013-08-22 23:22:47 +02:00
|
|
|
void wined3d_volume_upload_data(struct wined3d_volume *volume, const struct wined3d_context *context,
|
2013-08-22 14:57:56 +02:00
|
|
|
const struct wined3d_bo_address *data)
|
2011-01-20 19:52:01 +01:00
|
|
|
{
|
2011-07-27 23:21:25 +02:00
|
|
|
const struct wined3d_gl_info *gl_info = context->gl_info;
|
2011-01-20 19:52:01 +01:00
|
|
|
const struct wined3d_format *format = volume->resource.format;
|
2013-09-23 13:29:12 +02:00
|
|
|
UINT width = volume->resource.width;
|
|
|
|
UINT height = volume->resource.height;
|
2013-09-23 13:29:13 +02:00
|
|
|
UINT depth = volume->resource.depth;
|
2013-09-23 13:29:12 +02:00
|
|
|
BYTE *mem = data->addr;
|
2011-01-20 19:52:01 +01:00
|
|
|
|
2013-08-22 14:57:56 +02:00
|
|
|
TRACE("volume %p, context %p, level %u, format %s (%#x).\n",
|
|
|
|
volume, context, volume->texture_level, debug_d3dformat(format->id),
|
2013-08-22 14:57:54 +02:00
|
|
|
format->id);
|
2011-01-20 19:52:01 +01:00
|
|
|
|
2013-09-23 13:29:12 +02:00
|
|
|
if (format->convert)
|
|
|
|
{
|
|
|
|
UINT dst_row_pitch, dst_slice_pitch;
|
|
|
|
UINT src_row_pitch, src_slice_pitch;
|
|
|
|
UINT alignment = volume->resource.device->surface_alignment;
|
|
|
|
|
|
|
|
if (data->buffer_object)
|
|
|
|
ERR("Loading a converted volume from a PBO.\n");
|
|
|
|
if (format->flags & WINED3DFMT_FLAG_BLOCKS)
|
|
|
|
ERR("Converting a block-based format.\n");
|
|
|
|
|
|
|
|
dst_row_pitch = width * format->conv_byte_count;
|
|
|
|
dst_row_pitch = (dst_row_pitch + alignment - 1) & ~(alignment - 1);
|
|
|
|
dst_slice_pitch = dst_row_pitch * height;
|
|
|
|
|
|
|
|
wined3d_volume_get_pitch(volume, &src_row_pitch, &src_slice_pitch);
|
|
|
|
|
|
|
|
mem = HeapAlloc(GetProcessHeap(), 0, dst_slice_pitch * depth);
|
2013-09-23 13:29:13 +02:00
|
|
|
format->convert(data->addr, mem, src_row_pitch, src_slice_pitch,
|
|
|
|
dst_row_pitch, dst_slice_pitch, width, height, depth);
|
2013-09-23 13:29:12 +02:00
|
|
|
}
|
2013-08-22 14:57:56 +02:00
|
|
|
|
|
|
|
if (data->buffer_object)
|
|
|
|
{
|
|
|
|
GL_EXTCALL(glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, data->buffer_object));
|
|
|
|
checkGLcall("glBindBufferARB");
|
|
|
|
}
|
|
|
|
|
|
|
|
GL_EXTCALL(glTexSubImage3DEXT(GL_TEXTURE_3D, volume->texture_level, 0, 0, 0,
|
2013-09-23 13:29:12 +02:00
|
|
|
width, height, depth,
|
|
|
|
format->glFormat, format->glType, mem));
|
2013-08-22 14:57:56 +02:00
|
|
|
checkGLcall("glTexSubImage3D");
|
|
|
|
|
|
|
|
if (data->buffer_object)
|
|
|
|
{
|
|
|
|
GL_EXTCALL(glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, 0));
|
|
|
|
checkGLcall("glBindBufferARB");
|
|
|
|
}
|
2013-09-23 13:29:12 +02:00
|
|
|
|
|
|
|
if (mem != data->addr)
|
|
|
|
HeapFree(GetProcessHeap(), 0, mem);
|
2013-08-22 14:57:56 +02:00
|
|
|
}
|
|
|
|
|
2013-08-22 14:57:59 +02:00
|
|
|
static void wined3d_volume_validate_location(struct wined3d_volume *volume, DWORD location)
|
|
|
|
{
|
|
|
|
TRACE("Volume %p, setting %s.\n", volume, wined3d_debug_location(location));
|
|
|
|
volume->locations |= location;
|
|
|
|
TRACE("new location flags are %s.\n", wined3d_debug_location(volume->locations));
|
|
|
|
}
|
|
|
|
|
2013-08-22 23:22:47 +02:00
|
|
|
void wined3d_volume_invalidate_location(struct wined3d_volume *volume, DWORD location)
|
2013-08-22 14:57:59 +02:00
|
|
|
{
|
|
|
|
TRACE("Volume %p, clearing %s.\n", volume, wined3d_debug_location(location));
|
|
|
|
volume->locations &= ~location;
|
|
|
|
TRACE("new location flags are %s.\n", wined3d_debug_location(volume->locations));
|
|
|
|
}
|
|
|
|
|
2013-08-22 23:22:46 +02:00
|
|
|
/* Context activation is done by the caller. */
|
|
|
|
static void wined3d_volume_download_data(struct wined3d_volume *volume,
|
2013-08-08 16:42:29 +02:00
|
|
|
const struct wined3d_context *context, const struct wined3d_bo_address *data)
|
2013-08-22 23:22:46 +02:00
|
|
|
{
|
|
|
|
const struct wined3d_gl_info *gl_info = context->gl_info;
|
|
|
|
const struct wined3d_format *format = volume->resource.format;
|
|
|
|
|
2013-09-23 13:29:12 +02:00
|
|
|
if (format->convert)
|
|
|
|
{
|
|
|
|
FIXME("Attempting to download a converted volume, format %s.\n",
|
|
|
|
debug_d3dformat(format->id));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-08-08 16:42:29 +02:00
|
|
|
if (data->buffer_object)
|
|
|
|
{
|
|
|
|
GL_EXTCALL(glBindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, data->buffer_object));
|
|
|
|
checkGLcall("glBindBufferARB");
|
|
|
|
}
|
|
|
|
|
2013-08-22 23:22:46 +02:00
|
|
|
gl_info->gl_ops.gl.p_glGetTexImage(GL_TEXTURE_3D, volume->texture_level,
|
2013-08-08 16:42:29 +02:00
|
|
|
format->glFormat, format->glType, data->addr);
|
2013-08-22 23:22:46 +02:00
|
|
|
checkGLcall("glGetTexImage");
|
2013-08-08 16:42:29 +02:00
|
|
|
|
|
|
|
if (data->buffer_object)
|
|
|
|
{
|
|
|
|
GL_EXTCALL(glBindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, 0));
|
|
|
|
checkGLcall("glBindBufferARB");
|
|
|
|
}
|
|
|
|
|
2013-08-22 23:22:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void wined3d_volume_evict_sysmem(struct wined3d_volume *volume)
|
|
|
|
{
|
2013-09-16 10:57:25 +02:00
|
|
|
wined3d_resource_free_sysmem(&volume->resource);
|
2013-08-22 23:22:46 +02:00
|
|
|
wined3d_volume_invalidate_location(volume, WINED3D_LOCATION_SYSMEM);
|
|
|
|
}
|
|
|
|
|
2013-08-22 23:22:47 +02:00
|
|
|
static DWORD volume_access_from_location(DWORD location)
|
|
|
|
{
|
|
|
|
switch (location)
|
|
|
|
{
|
|
|
|
case WINED3D_LOCATION_DISCARDED:
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
case WINED3D_LOCATION_SYSMEM:
|
|
|
|
return WINED3D_RESOURCE_ACCESS_CPU;
|
|
|
|
|
2013-08-08 16:42:29 +02:00
|
|
|
case WINED3D_LOCATION_BUFFER:
|
2013-08-22 23:22:47 +02:00
|
|
|
case WINED3D_LOCATION_TEXTURE_RGB:
|
2013-08-26 02:01:29 +02:00
|
|
|
case WINED3D_LOCATION_TEXTURE_SRGB:
|
2013-08-22 23:22:47 +02:00
|
|
|
return WINED3D_RESOURCE_ACCESS_GPU;
|
|
|
|
|
|
|
|
default:
|
|
|
|
FIXME("Unhandled location %#x.\n", location);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-26 02:01:29 +02:00
|
|
|
/* Context activation is done by the caller. */
|
|
|
|
static void wined3d_volume_srgb_transfer(struct wined3d_volume *volume,
|
|
|
|
struct wined3d_context *context, BOOL dest_is_srgb)
|
|
|
|
{
|
|
|
|
struct wined3d_bo_address data;
|
|
|
|
/* Optimizations are possible, but the effort should be put into either
|
|
|
|
* implementing EXT_SRGB_DECODE in the driver or finding out why we
|
|
|
|
* picked the wrong copy for the original upload and fixing that.
|
|
|
|
*
|
2013-09-19 11:02:54 +02:00
|
|
|
* Also keep in mind that we want to avoid using resource.heap_memory
|
2013-08-26 02:01:29 +02:00
|
|
|
* for DEFAULT pool surfaces. */
|
|
|
|
|
|
|
|
WARN_(d3d_perf)("Performing slow rgb/srgb volume transfer.\n");
|
|
|
|
data.buffer_object = 0;
|
|
|
|
data.addr = HeapAlloc(GetProcessHeap(), 0, volume->resource.size);
|
|
|
|
if (!data.addr)
|
|
|
|
return;
|
|
|
|
|
|
|
|
volume_bind_and_dirtify(volume, context, !dest_is_srgb);
|
|
|
|
wined3d_volume_download_data(volume, context, &data);
|
|
|
|
volume_bind_and_dirtify(volume, context, dest_is_srgb);
|
|
|
|
wined3d_volume_upload_data(volume, context, &data);
|
|
|
|
|
|
|
|
HeapFree(GetProcessHeap(), 0, data.addr);
|
|
|
|
}
|
|
|
|
|
2013-09-23 13:29:12 +02:00
|
|
|
static BOOL wined3d_volume_can_evict(const struct wined3d_volume *volume)
|
|
|
|
{
|
|
|
|
if (volume->resource.pool != WINED3D_POOL_MANAGED)
|
|
|
|
return FALSE;
|
|
|
|
if (volume->download_count >= 10)
|
|
|
|
return FALSE;
|
|
|
|
if (volume->resource.format->convert)
|
|
|
|
return FALSE;
|
2013-09-23 13:29:16 +02:00
|
|
|
if (volume->flags & WINED3D_VFLAG_CLIENT_STORAGE)
|
|
|
|
return FALSE;
|
2013-09-23 13:29:12 +02:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
2013-08-22 14:57:59 +02:00
|
|
|
/* Context activation is done by the caller. */
|
|
|
|
static void wined3d_volume_load_location(struct wined3d_volume *volume,
|
|
|
|
struct wined3d_context *context, DWORD location)
|
|
|
|
{
|
2013-08-22 23:22:47 +02:00
|
|
|
DWORD required_access = volume_access_from_location(location);
|
|
|
|
|
2013-08-22 14:57:59 +02:00
|
|
|
TRACE("Volume %p, loading %s, have %s.\n", volume, wined3d_debug_location(location),
|
|
|
|
wined3d_debug_location(volume->locations));
|
|
|
|
|
|
|
|
if ((volume->locations & location) == location)
|
|
|
|
{
|
|
|
|
TRACE("Location(s) already up to date.\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-08-22 23:22:47 +02:00
|
|
|
if ((volume->resource.access_flags & required_access) != required_access)
|
2013-08-22 14:57:59 +02:00
|
|
|
{
|
2013-08-22 23:22:47 +02:00
|
|
|
ERR("Operation requires %#x access, but volume only has %#x.\n",
|
|
|
|
required_access, volume->resource.access_flags);
|
|
|
|
return;
|
2013-08-22 14:57:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
switch (location)
|
|
|
|
{
|
|
|
|
case WINED3D_LOCATION_TEXTURE_RGB:
|
2013-08-26 02:01:29 +02:00
|
|
|
case WINED3D_LOCATION_TEXTURE_SRGB:
|
|
|
|
if ((location == WINED3D_LOCATION_TEXTURE_RGB
|
|
|
|
&& !(volume->flags & WINED3D_VFLAG_ALLOCATED))
|
|
|
|
|| (location == WINED3D_LOCATION_TEXTURE_SRGB
|
|
|
|
&& !(volume->flags & WINED3D_VFLAG_SRGB_ALLOCATED)))
|
|
|
|
ERR("Trying to load (s)RGB texture without prior allocation.\n");
|
2013-08-22 14:57:59 +02:00
|
|
|
|
|
|
|
if (volume->locations & WINED3D_LOCATION_DISCARDED)
|
|
|
|
{
|
|
|
|
TRACE("Volume previously discarded, nothing to do.\n");
|
|
|
|
wined3d_volume_invalidate_location(volume, WINED3D_LOCATION_DISCARDED);
|
|
|
|
}
|
|
|
|
else if (volume->locations & WINED3D_LOCATION_SYSMEM)
|
|
|
|
{
|
2013-09-19 11:02:54 +02:00
|
|
|
struct wined3d_bo_address data = {0, volume->resource.heap_memory};
|
2013-08-22 14:57:59 +02:00
|
|
|
wined3d_volume_upload_data(volume, context, &data);
|
|
|
|
}
|
2013-08-08 16:42:29 +02:00
|
|
|
else if (volume->locations & WINED3D_LOCATION_BUFFER)
|
|
|
|
{
|
|
|
|
struct wined3d_bo_address data = {volume->pbo, NULL};
|
|
|
|
wined3d_volume_upload_data(volume, context, &data);
|
|
|
|
}
|
2013-08-26 02:01:29 +02:00
|
|
|
else if (volume->locations & WINED3D_LOCATION_TEXTURE_RGB)
|
|
|
|
{
|
|
|
|
wined3d_volume_srgb_transfer(volume, context, TRUE);
|
|
|
|
}
|
|
|
|
else if (volume->locations & WINED3D_LOCATION_TEXTURE_SRGB)
|
|
|
|
{
|
|
|
|
wined3d_volume_srgb_transfer(volume, context, FALSE);
|
|
|
|
}
|
2013-08-22 14:57:59 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
FIXME("Implement texture loading from %s.\n", wined3d_debug_location(volume->locations));
|
|
|
|
return;
|
|
|
|
}
|
2013-08-26 02:01:29 +02:00
|
|
|
wined3d_volume_validate_location(volume, location);
|
2013-08-22 23:22:46 +02:00
|
|
|
|
2013-09-23 13:29:12 +02:00
|
|
|
if (wined3d_volume_can_evict(volume))
|
2013-08-22 23:22:46 +02:00
|
|
|
wined3d_volume_evict_sysmem(volume);
|
|
|
|
|
2013-08-22 14:57:59 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case WINED3D_LOCATION_SYSMEM:
|
2013-09-19 11:02:54 +02:00
|
|
|
if (!volume->resource.heap_memory)
|
2013-08-22 14:57:59 +02:00
|
|
|
ERR("Trying to load WINED3D_LOCATION_SYSMEM without setting it up first.\n");
|
|
|
|
|
|
|
|
if (volume->locations & WINED3D_LOCATION_DISCARDED)
|
|
|
|
{
|
|
|
|
TRACE("Volume previously discarded, nothing to do.\n");
|
|
|
|
wined3d_volume_invalidate_location(volume, WINED3D_LOCATION_DISCARDED);
|
|
|
|
}
|
2013-08-26 02:01:29 +02:00
|
|
|
else if (volume->locations & (WINED3D_LOCATION_TEXTURE_RGB | WINED3D_LOCATION_TEXTURE_SRGB))
|
2013-08-22 23:22:46 +02:00
|
|
|
{
|
2013-09-19 11:02:54 +02:00
|
|
|
struct wined3d_bo_address data = {0, volume->resource.heap_memory};
|
2013-08-26 02:01:29 +02:00
|
|
|
|
|
|
|
if (volume->locations & WINED3D_LOCATION_TEXTURE_RGB)
|
|
|
|
volume_bind_and_dirtify(volume, context, FALSE);
|
|
|
|
else
|
|
|
|
volume_bind_and_dirtify(volume, context, TRUE);
|
|
|
|
|
2013-08-22 23:22:46 +02:00
|
|
|
volume->download_count++;
|
2013-08-08 16:42:29 +02:00
|
|
|
wined3d_volume_download_data(volume, context, &data);
|
2013-08-22 23:22:46 +02:00
|
|
|
}
|
2013-08-22 14:57:59 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
FIXME("Implement WINED3D_LOCATION_SYSMEM loading from %s.\n",
|
|
|
|
wined3d_debug_location(volume->locations));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
wined3d_volume_validate_location(volume, WINED3D_LOCATION_SYSMEM);
|
|
|
|
break;
|
|
|
|
|
2013-08-08 16:42:29 +02:00
|
|
|
case WINED3D_LOCATION_BUFFER:
|
|
|
|
if (!volume->pbo || !(volume->flags & WINED3D_VFLAG_PBO))
|
|
|
|
ERR("Trying to load WINED3D_LOCATION_BUFFER without setting it up first.\n");
|
|
|
|
|
|
|
|
if (volume->locations & WINED3D_LOCATION_DISCARDED)
|
|
|
|
{
|
|
|
|
TRACE("Volume previously discarded, nothing to do.\n");
|
|
|
|
wined3d_volume_invalidate_location(volume, WINED3D_LOCATION_DISCARDED);
|
|
|
|
}
|
2013-08-26 02:01:29 +02:00
|
|
|
else if (volume->locations & (WINED3D_LOCATION_TEXTURE_RGB | WINED3D_LOCATION_TEXTURE_SRGB))
|
2013-08-08 16:42:29 +02:00
|
|
|
{
|
|
|
|
struct wined3d_bo_address data = {volume->pbo, NULL};
|
2013-08-26 02:01:29 +02:00
|
|
|
|
|
|
|
if (volume->locations & WINED3D_LOCATION_TEXTURE_RGB)
|
|
|
|
volume_bind_and_dirtify(volume, context, FALSE);
|
|
|
|
else
|
|
|
|
volume_bind_and_dirtify(volume, context, TRUE);
|
|
|
|
|
2013-08-08 16:42:29 +02:00
|
|
|
wined3d_volume_download_data(volume, context, &data);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
FIXME("Implement WINED3D_LOCATION_BUFFER loading from %s.\n",
|
|
|
|
wined3d_debug_location(volume->locations));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
wined3d_volume_validate_location(volume, WINED3D_LOCATION_BUFFER);
|
|
|
|
break;
|
|
|
|
|
2013-08-22 14:57:59 +02:00
|
|
|
default:
|
|
|
|
FIXME("Implement %s loading from %s.\n", wined3d_debug_location(location),
|
|
|
|
wined3d_debug_location(volume->locations));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-22 14:57:56 +02:00
|
|
|
/* Context activation is done by the caller. */
|
|
|
|
void wined3d_volume_load(struct wined3d_volume *volume, struct wined3d_context *context, BOOL srgb_mode)
|
|
|
|
{
|
2013-08-26 02:01:29 +02:00
|
|
|
volume_bind_and_dirtify(volume, context, srgb_mode);
|
2011-01-20 19:52:01 +01:00
|
|
|
|
2013-08-26 02:01:29 +02:00
|
|
|
if (srgb_mode)
|
2013-08-22 14:57:55 +02:00
|
|
|
{
|
2013-08-26 02:01:29 +02:00
|
|
|
if (!(volume->flags & WINED3D_VFLAG_SRGB_ALLOCATED))
|
|
|
|
{
|
|
|
|
wined3d_volume_allocate_texture(volume, context, TRUE);
|
|
|
|
volume->flags |= WINED3D_VFLAG_SRGB_ALLOCATED;
|
|
|
|
}
|
|
|
|
|
|
|
|
wined3d_volume_load_location(volume, context, WINED3D_LOCATION_TEXTURE_SRGB);
|
2013-08-22 14:57:55 +02:00
|
|
|
}
|
2013-08-26 02:01:29 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
if (!(volume->flags & WINED3D_VFLAG_ALLOCATED))
|
|
|
|
{
|
|
|
|
wined3d_volume_allocate_texture(volume, context, FALSE);
|
|
|
|
volume->flags |= WINED3D_VFLAG_ALLOCATED;
|
|
|
|
}
|
2013-08-22 14:57:55 +02:00
|
|
|
|
2013-08-26 02:01:29 +02:00
|
|
|
wined3d_volume_load_location(volume, context, WINED3D_LOCATION_TEXTURE_RGB);
|
|
|
|
}
|
2011-01-20 19:52:01 +01:00
|
|
|
}
|
|
|
|
|
2013-08-08 16:42:29 +02:00
|
|
|
/* Context activation is done by the caller. */
|
|
|
|
static void wined3d_volume_prepare_pbo(struct wined3d_volume *volume, struct wined3d_context *context)
|
|
|
|
{
|
|
|
|
const struct wined3d_gl_info *gl_info = context->gl_info;
|
|
|
|
|
|
|
|
if (volume->pbo)
|
|
|
|
return;
|
|
|
|
|
|
|
|
GL_EXTCALL(glGenBuffersARB(1, &volume->pbo));
|
|
|
|
GL_EXTCALL(glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, volume->pbo));
|
|
|
|
GL_EXTCALL(glBufferDataARB(GL_PIXEL_UNPACK_BUFFER_ARB, volume->resource.size, NULL, GL_STREAM_DRAW_ARB));
|
|
|
|
GL_EXTCALL(glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, 0));
|
|
|
|
checkGLcall("Create PBO");
|
|
|
|
|
|
|
|
TRACE("Created PBO %u for volume %p.\n", volume->pbo, volume);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void wined3d_volume_free_pbo(struct wined3d_volume *volume)
|
|
|
|
{
|
|
|
|
struct wined3d_context *context = context_acquire(volume->resource.device, NULL);
|
|
|
|
const struct wined3d_gl_info *gl_info = context->gl_info;
|
|
|
|
|
|
|
|
TRACE("Deleting PBO %u belonging to volume %p.\n", volume->pbo, volume);
|
|
|
|
GL_EXTCALL(glDeleteBuffersARB(1, &volume->pbo));
|
|
|
|
checkGLcall("glDeleteBuffersARB");
|
|
|
|
volume->pbo = 0;
|
|
|
|
context_release(context);
|
|
|
|
}
|
|
|
|
|
2011-03-01 09:47:56 +01:00
|
|
|
static void volume_unload(struct wined3d_resource *resource)
|
2011-02-28 08:05:39 +01:00
|
|
|
{
|
2013-08-22 14:57:55 +02:00
|
|
|
struct wined3d_volume *volume = volume_from_resource(resource);
|
2013-08-22 14:57:59 +02:00
|
|
|
struct wined3d_device *device = volume->resource.device;
|
|
|
|
struct wined3d_context *context;
|
|
|
|
|
|
|
|
if (volume->resource.pool == WINED3D_POOL_DEFAULT)
|
|
|
|
ERR("Unloading DEFAULT pool volume.\n");
|
2013-08-22 14:57:55 +02:00
|
|
|
|
2011-02-28 08:05:39 +01:00
|
|
|
TRACE("texture %p.\n", resource);
|
|
|
|
|
2013-08-22 23:22:45 +02:00
|
|
|
if (volume_prepare_system_memory(volume))
|
|
|
|
{
|
|
|
|
context = context_acquire(device, NULL);
|
|
|
|
wined3d_volume_load_location(volume, context, WINED3D_LOCATION_SYSMEM);
|
|
|
|
context_release(context);
|
|
|
|
wined3d_volume_invalidate_location(volume, ~WINED3D_LOCATION_SYSMEM);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ERR("Out of memory when unloading volume %p.\n", volume);
|
|
|
|
wined3d_volume_validate_location(volume, WINED3D_LOCATION_DISCARDED);
|
|
|
|
wined3d_volume_invalidate_location(volume, ~WINED3D_LOCATION_DISCARDED);
|
|
|
|
}
|
2013-08-22 14:57:59 +02:00
|
|
|
|
2013-08-08 16:42:29 +02:00
|
|
|
if (volume->pbo)
|
|
|
|
{
|
|
|
|
/* Should not happen because only dynamic default pool volumes
|
|
|
|
* have a buffer, and those are not evicted by device_evit_managed_resources
|
|
|
|
* and must be freed before a non-ex device reset. */
|
|
|
|
ERR("Unloading a volume with a buffer\n");
|
|
|
|
wined3d_volume_free_pbo(volume);
|
|
|
|
}
|
|
|
|
|
2013-08-22 14:57:59 +02:00
|
|
|
/* The texture name is managed by the container. */
|
2013-09-23 13:29:16 +02:00
|
|
|
volume->flags &= ~(WINED3D_VFLAG_ALLOCATED | WINED3D_VFLAG_SRGB_ALLOCATED
|
|
|
|
| WINED3D_VFLAG_CLIENT_STORAGE);
|
2011-02-28 08:05:39 +01:00
|
|
|
|
|
|
|
resource_unload(resource);
|
|
|
|
}
|
|
|
|
|
2011-04-14 22:41:47 +02:00
|
|
|
ULONG CDECL wined3d_volume_incref(struct wined3d_volume *volume)
|
2005-01-17 14:44:57 +01:00
|
|
|
{
|
2011-04-15 18:33:38 +02:00
|
|
|
ULONG refcount;
|
|
|
|
|
|
|
|
if (volume->container)
|
|
|
|
{
|
|
|
|
TRACE("Forwarding to container %p.\n", volume->container);
|
|
|
|
return wined3d_texture_incref(volume->container);
|
|
|
|
}
|
|
|
|
|
|
|
|
refcount = InterlockedIncrement(&volume->resource.ref);
|
2009-12-21 23:17:24 +01:00
|
|
|
|
2011-04-14 22:41:47 +02:00
|
|
|
TRACE("%p increasing refcount to %u.\n", volume, refcount);
|
2009-12-21 23:17:24 +01:00
|
|
|
|
2011-04-14 22:41:47 +02:00
|
|
|
return refcount;
|
2005-01-17 14:44:57 +01:00
|
|
|
}
|
|
|
|
|
2011-04-14 22:41:47 +02:00
|
|
|
ULONG CDECL wined3d_volume_decref(struct wined3d_volume *volume)
|
|
|
|
{
|
2011-04-15 18:33:38 +02:00
|
|
|
ULONG refcount;
|
|
|
|
|
|
|
|
if (volume->container)
|
|
|
|
{
|
|
|
|
TRACE("Forwarding to container %p.\n", volume->container);
|
|
|
|
return wined3d_texture_decref(volume->container);
|
|
|
|
}
|
|
|
|
|
|
|
|
refcount = InterlockedDecrement(&volume->resource.ref);
|
2011-04-14 22:41:47 +02:00
|
|
|
|
|
|
|
TRACE("%p decreasing refcount to %u.\n", volume, refcount);
|
2010-09-14 13:38:39 +02:00
|
|
|
|
2011-04-14 22:41:47 +02:00
|
|
|
if (!refcount)
|
2010-09-14 13:38:39 +02:00
|
|
|
{
|
2013-08-08 16:42:29 +02:00
|
|
|
if (volume->pbo)
|
|
|
|
wined3d_volume_free_pbo(volume);
|
|
|
|
|
2011-04-14 22:41:47 +02:00
|
|
|
resource_cleanup(&volume->resource);
|
|
|
|
volume->resource.parent_ops->wined3d_object_destroyed(volume->resource.parent);
|
|
|
|
HeapFree(GetProcessHeap(), 0, volume);
|
2005-01-17 14:44:57 +01:00
|
|
|
}
|
2011-04-14 22:41:47 +02:00
|
|
|
|
|
|
|
return refcount;
|
2005-01-17 14:44:57 +01:00
|
|
|
}
|
|
|
|
|
2011-04-14 22:41:47 +02:00
|
|
|
void * CDECL wined3d_volume_get_parent(const struct wined3d_volume *volume)
|
2010-08-31 18:41:40 +02:00
|
|
|
{
|
2011-04-14 22:41:47 +02:00
|
|
|
TRACE("volume %p.\n", volume);
|
2010-08-31 18:41:40 +02:00
|
|
|
|
2011-04-14 22:41:47 +02:00
|
|
|
return volume->resource.parent;
|
2005-01-17 14:44:57 +01:00
|
|
|
}
|
|
|
|
|
2011-04-14 22:41:47 +02:00
|
|
|
DWORD CDECL wined3d_volume_set_priority(struct wined3d_volume *volume, DWORD priority)
|
2011-01-07 10:16:40 +01:00
|
|
|
{
|
2011-04-14 22:41:47 +02:00
|
|
|
return resource_set_priority(&volume->resource, priority);
|
2005-03-29 21:01:00 +02:00
|
|
|
}
|
|
|
|
|
2011-04-14 22:41:47 +02:00
|
|
|
DWORD CDECL wined3d_volume_get_priority(const struct wined3d_volume *volume)
|
2011-01-07 10:16:39 +01:00
|
|
|
{
|
2011-04-14 22:41:47 +02:00
|
|
|
return resource_get_priority(&volume->resource);
|
2005-03-29 21:01:00 +02:00
|
|
|
}
|
|
|
|
|
2011-04-14 22:41:47 +02:00
|
|
|
void CDECL wined3d_volume_preload(struct wined3d_volume *volume)
|
|
|
|
{
|
|
|
|
FIXME("volume %p stub!\n", volume);
|
2005-01-17 14:44:57 +01:00
|
|
|
}
|
|
|
|
|
2011-04-14 22:41:47 +02:00
|
|
|
struct wined3d_resource * CDECL wined3d_volume_get_resource(struct wined3d_volume *volume)
|
2010-08-25 20:46:50 +02:00
|
|
|
{
|
2011-04-14 22:41:47 +02:00
|
|
|
TRACE("volume %p.\n", volume);
|
2010-09-06 22:18:54 +02:00
|
|
|
|
2011-04-14 22:41:47 +02:00
|
|
|
return &volume->resource;
|
2005-01-17 14:44:57 +01:00
|
|
|
}
|
|
|
|
|
2013-09-18 12:24:56 +02:00
|
|
|
static BOOL volume_check_block_align(const struct wined3d_volume *volume,
|
|
|
|
const struct wined3d_box *box)
|
|
|
|
{
|
|
|
|
UINT width_mask, height_mask;
|
|
|
|
const struct wined3d_format *format = volume->resource.format;
|
|
|
|
|
|
|
|
if (!box)
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
/* This assumes power of two block sizes, but NPOT block sizes would be
|
|
|
|
* silly anyway.
|
|
|
|
*
|
|
|
|
* This also assumes that the format's block depth is 1. */
|
|
|
|
width_mask = format->block_width - 1;
|
|
|
|
height_mask = format->block_height - 1;
|
|
|
|
|
|
|
|
if (box->left & width_mask)
|
|
|
|
return FALSE;
|
|
|
|
if (box->top & height_mask)
|
|
|
|
return FALSE;
|
|
|
|
if (box->right & width_mask && box->right != volume->resource.width)
|
|
|
|
return FALSE;
|
|
|
|
if (box->bottom & height_mask && box->bottom != volume->resource.height)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2013-09-18 12:24:57 +02:00
|
|
|
static BOOL wined3d_volume_check_box_dimensions(const struct wined3d_volume *volume,
|
|
|
|
const struct wined3d_box *box)
|
|
|
|
{
|
|
|
|
if (!box)
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
if (box->left >= box->right)
|
|
|
|
return FALSE;
|
|
|
|
if (box->top >= box->bottom)
|
|
|
|
return FALSE;
|
|
|
|
if (box->front >= box->back)
|
|
|
|
return FALSE;
|
|
|
|
if (box->right > volume->resource.width)
|
|
|
|
return FALSE;
|
|
|
|
if (box->bottom > volume->resource.height)
|
|
|
|
return FALSE;
|
|
|
|
if (box->back > volume->resource.depth)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2011-04-14 22:41:47 +02:00
|
|
|
HRESULT CDECL wined3d_volume_map(struct wined3d_volume *volume,
|
2012-04-12 22:49:04 +02:00
|
|
|
struct wined3d_map_desc *map_desc, const struct wined3d_box *box, DWORD flags)
|
2010-10-14 13:04:02 +02:00
|
|
|
{
|
2013-08-08 16:42:29 +02:00
|
|
|
struct wined3d_device *device = volume->resource.device;
|
|
|
|
struct wined3d_context *context;
|
|
|
|
const struct wined3d_gl_info *gl_info;
|
|
|
|
BYTE *base_memory;
|
2013-09-18 12:24:56 +02:00
|
|
|
const struct wined3d_format *format = volume->resource.format;
|
2013-08-08 16:42:29 +02:00
|
|
|
|
2012-04-12 22:49:04 +02:00
|
|
|
TRACE("volume %p, map_desc %p, box %p, flags %#x.\n",
|
|
|
|
volume, map_desc, box, flags);
|
2005-01-17 14:44:57 +01:00
|
|
|
|
2013-09-18 12:24:55 +02:00
|
|
|
map_desc->data = NULL;
|
2013-08-26 02:01:26 +02:00
|
|
|
if (!(volume->resource.access_flags & WINED3D_RESOURCE_ACCESS_CPU))
|
|
|
|
{
|
|
|
|
WARN("Volume %p is not CPU accessible.\n", volume);
|
2013-09-18 12:24:55 +02:00
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
}
|
|
|
|
if (volume->resource.map_count)
|
|
|
|
{
|
|
|
|
WARN("Volume is already mapped.\n");
|
2013-08-26 02:01:26 +02:00
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
}
|
2013-09-18 12:24:57 +02:00
|
|
|
if (!wined3d_volume_check_box_dimensions(volume, box))
|
|
|
|
{
|
|
|
|
WARN("Map box is invalid.\n");
|
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
}
|
2013-09-18 12:24:56 +02:00
|
|
|
if ((format->flags & WINED3DFMT_FLAG_BLOCKS) && !volume_check_block_align(volume, box))
|
|
|
|
{
|
|
|
|
WARN("Map box is misaligned for %ux%u blocks.\n",
|
|
|
|
format->block_width, format->block_height);
|
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
}
|
|
|
|
|
2013-08-26 02:01:28 +02:00
|
|
|
flags = wined3d_resource_sanitize_map_flags(&volume->resource, flags);
|
2013-08-26 02:01:26 +02:00
|
|
|
|
2013-08-08 16:42:29 +02:00
|
|
|
if (volume->flags & WINED3D_VFLAG_PBO)
|
2013-08-21 15:15:49 +02:00
|
|
|
{
|
2013-08-08 16:42:29 +02:00
|
|
|
context = context_acquire(device, NULL);
|
|
|
|
gl_info = context->gl_info;
|
|
|
|
|
|
|
|
wined3d_volume_prepare_pbo(volume, context);
|
2013-08-26 02:01:28 +02:00
|
|
|
if (flags & WINED3D_MAP_DISCARD)
|
|
|
|
wined3d_volume_validate_location(volume, WINED3D_LOCATION_BUFFER);
|
|
|
|
else
|
|
|
|
wined3d_volume_load_location(volume, context, WINED3D_LOCATION_BUFFER);
|
2013-08-08 16:42:29 +02:00
|
|
|
|
|
|
|
GL_EXTCALL(glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, volume->pbo));
|
2013-08-26 02:01:28 +02:00
|
|
|
|
|
|
|
if (gl_info->supported[ARB_MAP_BUFFER_RANGE])
|
|
|
|
{
|
|
|
|
GLbitfield mapflags = wined3d_resource_gl_map_flags(flags);
|
|
|
|
mapflags &= ~GL_MAP_FLUSH_EXPLICIT_BIT;
|
|
|
|
base_memory = GL_EXTCALL(glMapBufferRange(GL_PIXEL_UNPACK_BUFFER_ARB,
|
|
|
|
0, volume->resource.size, mapflags));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-09-19 11:02:55 +02:00
|
|
|
GLenum access = wined3d_resource_gl_legacy_map_flags(flags);
|
|
|
|
base_memory = GL_EXTCALL(glMapBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, access));
|
2013-08-26 02:01:28 +02:00
|
|
|
}
|
|
|
|
|
2013-08-08 16:42:29 +02:00
|
|
|
GL_EXTCALL(glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, 0));
|
|
|
|
checkGLcall("Map PBO");
|
2007-02-20 23:02:30 +01:00
|
|
|
|
2013-08-22 14:57:59 +02:00
|
|
|
context_release(context);
|
|
|
|
}
|
2013-08-08 16:42:29 +02:00
|
|
|
else
|
|
|
|
{
|
2013-08-26 02:01:28 +02:00
|
|
|
if (!volume_prepare_system_memory(volume))
|
|
|
|
{
|
|
|
|
WARN("Out of memory.\n");
|
|
|
|
map_desc->data = NULL;
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (flags & WINED3D_MAP_DISCARD)
|
|
|
|
{
|
|
|
|
wined3d_volume_validate_location(volume, WINED3D_LOCATION_SYSMEM);
|
|
|
|
}
|
|
|
|
else if (!(volume->locations & WINED3D_LOCATION_SYSMEM))
|
2013-08-08 16:42:29 +02:00
|
|
|
{
|
|
|
|
context = context_acquire(device, NULL);
|
|
|
|
wined3d_volume_load_location(volume, context, WINED3D_LOCATION_SYSMEM);
|
|
|
|
context_release(context);
|
|
|
|
}
|
2013-09-19 11:02:54 +02:00
|
|
|
base_memory = volume->resource.heap_memory;
|
2013-08-08 16:42:29 +02:00
|
|
|
}
|
2013-08-22 14:57:59 +02:00
|
|
|
|
2013-08-08 16:42:29 +02:00
|
|
|
TRACE("Base memory pointer %p.\n", base_memory);
|
2005-01-17 14:44:57 +01:00
|
|
|
|
2013-09-18 12:24:56 +02:00
|
|
|
if (format->flags & WINED3DFMT_FLAG_BROKEN_PITCH)
|
|
|
|
{
|
|
|
|
map_desc->row_pitch = volume->resource.width * format->byte_count;
|
|
|
|
map_desc->slice_pitch = map_desc->row_pitch * volume->resource.height;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
wined3d_volume_get_pitch(volume, &map_desc->row_pitch, &map_desc->slice_pitch);
|
|
|
|
}
|
|
|
|
|
2011-04-14 22:41:47 +02:00
|
|
|
if (!box)
|
|
|
|
{
|
2005-01-17 14:44:57 +01:00
|
|
|
TRACE("No box supplied - all is ok\n");
|
2013-08-08 16:42:29 +02:00
|
|
|
map_desc->data = base_memory;
|
2011-04-14 22:41:47 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-12-06 22:57:47 +01:00
|
|
|
TRACE("Lock Box (%p) = l %u, t %u, r %u, b %u, fr %u, ba %u\n",
|
|
|
|
box, box->left, box->top, box->right, box->bottom, box->front, box->back);
|
2013-09-18 12:24:56 +02:00
|
|
|
|
|
|
|
if ((format->flags & (WINED3DFMT_FLAG_BLOCKS | WINED3DFMT_FLAG_BROKEN_PITCH)) == WINED3DFMT_FLAG_BLOCKS)
|
|
|
|
{
|
|
|
|
/* Compressed textures are block based, so calculate the offset of
|
|
|
|
* the block that contains the top-left pixel of the locked rectangle. */
|
|
|
|
map_desc->data = base_memory
|
|
|
|
+ (box->front * map_desc->slice_pitch)
|
|
|
|
+ ((box->top / format->block_height) * map_desc->row_pitch)
|
|
|
|
+ ((box->left / format->block_width) * format->block_byte_count);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
map_desc->data = base_memory
|
|
|
|
+ (map_desc->slice_pitch * box->front)
|
|
|
|
+ (map_desc->row_pitch * box->top)
|
|
|
|
+ (box->left * volume->resource.format->byte_count);
|
|
|
|
}
|
2005-01-17 14:44:57 +01:00
|
|
|
}
|
2005-07-13 16:15:54 +02:00
|
|
|
|
2012-06-18 17:19:42 +02:00
|
|
|
if (!(flags & (WINED3D_MAP_NO_DIRTY_UPDATE | WINED3D_MAP_READONLY)))
|
2010-08-16 20:00:24 +02:00
|
|
|
{
|
2013-09-09 10:26:17 +02:00
|
|
|
wined3d_texture_set_dirty(volume->container);
|
2013-08-08 16:42:29 +02:00
|
|
|
|
|
|
|
if (volume->flags & WINED3D_VFLAG_PBO)
|
|
|
|
wined3d_volume_invalidate_location(volume, ~WINED3D_LOCATION_BUFFER);
|
|
|
|
else
|
|
|
|
wined3d_volume_invalidate_location(volume, ~WINED3D_LOCATION_SYSMEM);
|
2005-01-17 14:44:57 +01:00
|
|
|
}
|
|
|
|
|
2013-09-18 12:24:55 +02:00
|
|
|
volume->resource.map_count++;
|
2011-04-14 22:41:47 +02:00
|
|
|
|
|
|
|
TRACE("Returning memory %p, row pitch %d, slice pitch %d.\n",
|
2012-04-12 22:49:04 +02:00
|
|
|
map_desc->data, map_desc->row_pitch, map_desc->slice_pitch);
|
2011-04-14 22:41:47 +02:00
|
|
|
|
2006-04-07 12:51:12 +02:00
|
|
|
return WINED3D_OK;
|
2005-01-17 14:44:57 +01:00
|
|
|
}
|
|
|
|
|
2011-04-14 22:41:47 +02:00
|
|
|
struct wined3d_volume * CDECL wined3d_volume_from_resource(struct wined3d_resource *resource)
|
2011-03-14 21:02:57 +01:00
|
|
|
{
|
2011-04-14 22:41:47 +02:00
|
|
|
return volume_from_resource(resource);
|
2011-03-14 21:02:57 +01:00
|
|
|
}
|
|
|
|
|
2011-04-14 22:41:47 +02:00
|
|
|
HRESULT CDECL wined3d_volume_unmap(struct wined3d_volume *volume)
|
2010-10-14 13:04:02 +02:00
|
|
|
{
|
2011-04-14 22:41:47 +02:00
|
|
|
TRACE("volume %p.\n", volume);
|
|
|
|
|
2013-09-18 12:24:55 +02:00
|
|
|
if (!volume->resource.map_count)
|
2009-12-16 19:55:57 +01:00
|
|
|
{
|
2013-09-18 12:24:55 +02:00
|
|
|
WARN("Trying to unlock an unlocked volume %p.\n", volume);
|
2009-12-16 19:55:57 +01:00
|
|
|
return WINED3DERR_INVALIDCALL;
|
2005-01-17 14:44:57 +01:00
|
|
|
}
|
2011-04-14 22:41:47 +02:00
|
|
|
|
2013-08-08 16:42:29 +02:00
|
|
|
if (volume->flags & WINED3D_VFLAG_PBO)
|
|
|
|
{
|
|
|
|
struct wined3d_device *device = volume->resource.device;
|
|
|
|
struct wined3d_context *context = context_acquire(device, NULL);
|
|
|
|
const struct wined3d_gl_info *gl_info = context->gl_info;
|
|
|
|
|
|
|
|
GL_EXTCALL(glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, volume->pbo));
|
|
|
|
GL_EXTCALL(glUnmapBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB));
|
|
|
|
GL_EXTCALL(glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, 0));
|
|
|
|
checkGLcall("Unmap PBO");
|
|
|
|
|
|
|
|
context_release(context);
|
|
|
|
}
|
|
|
|
|
2013-09-18 12:24:55 +02:00
|
|
|
volume->resource.map_count--;
|
2011-04-14 22:41:47 +02:00
|
|
|
|
2006-04-07 12:51:12 +02:00
|
|
|
return WINED3D_OK;
|
2005-01-17 14:44:57 +01:00
|
|
|
}
|
|
|
|
|
2011-02-28 08:05:39 +01:00
|
|
|
static const struct wined3d_resource_ops volume_resource_ops =
|
|
|
|
{
|
|
|
|
volume_unload,
|
|
|
|
};
|
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
static HRESULT volume_init(struct wined3d_volume *volume, struct wined3d_device *device, UINT width,
|
2013-08-22 14:57:54 +02:00
|
|
|
UINT height, UINT depth, UINT level, DWORD usage, enum wined3d_format_id format_id,
|
|
|
|
enum wined3d_pool pool, void *parent, const struct wined3d_parent_ops *parent_ops)
|
2009-09-16 08:37:16 +02:00
|
|
|
{
|
|
|
|
const struct wined3d_gl_info *gl_info = &device->adapter->gl_info;
|
2010-08-30 20:29:49 +02:00
|
|
|
const struct wined3d_format *format = wined3d_get_format(gl_info, format_id);
|
2009-09-16 08:37:16 +02:00
|
|
|
HRESULT hr;
|
2013-08-21 15:15:47 +02:00
|
|
|
UINT size;
|
2009-09-16 08:37:16 +02:00
|
|
|
|
|
|
|
if (!gl_info->supported[EXT_TEXTURE3D])
|
|
|
|
{
|
|
|
|
WARN("Volume cannot be created - no volume texture support.\n");
|
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
}
|
2013-08-26 02:01:32 +02:00
|
|
|
/* TODO: Write tests for other resources and move this check
|
|
|
|
* to resource_init, if applicable. */
|
|
|
|
if (usage & WINED3DUSAGE_DYNAMIC
|
|
|
|
&& (pool == WINED3D_POOL_MANAGED || pool == WINED3D_POOL_SCRATCH))
|
|
|
|
{
|
|
|
|
WARN("Attempted to create a DYNAMIC texture in pool %u.\n", pool);
|
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
}
|
2009-09-16 08:37:16 +02:00
|
|
|
|
2013-08-21 15:15:47 +02:00
|
|
|
size = wined3d_format_calculate_size(format, device->surface_alignment, width, height, depth);
|
|
|
|
|
2012-01-17 21:13:36 +01:00
|
|
|
hr = resource_init(&volume->resource, device, WINED3D_RTYPE_VOLUME, format,
|
2012-01-08 21:15:00 +01:00
|
|
|
WINED3D_MULTISAMPLE_NONE, 0, usage, pool, width, height, depth,
|
2013-08-21 15:15:47 +02:00
|
|
|
size, parent, parent_ops, &volume_resource_ops);
|
2009-09-16 08:37:16 +02:00
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
|
|
|
WARN("Failed to initialize resource, returning %#x.\n", hr);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2013-08-22 14:57:54 +02:00
|
|
|
volume->texture_level = level;
|
2013-08-22 14:57:59 +02:00
|
|
|
volume->locations = WINED3D_LOCATION_DISCARDED;
|
2013-08-22 14:57:54 +02:00
|
|
|
|
2013-08-08 16:42:29 +02:00
|
|
|
if (pool == WINED3D_POOL_DEFAULT && usage & WINED3DUSAGE_DYNAMIC
|
2013-09-23 13:29:12 +02:00
|
|
|
&& gl_info->supported[ARB_PIXEL_BUFFER_OBJECT]
|
|
|
|
&& !format->convert)
|
2013-08-08 16:42:29 +02:00
|
|
|
{
|
2013-09-16 10:57:25 +02:00
|
|
|
wined3d_resource_free_sysmem(&volume->resource);
|
2013-08-08 16:42:29 +02:00
|
|
|
volume->flags |= WINED3D_VFLAG_PBO;
|
|
|
|
}
|
|
|
|
|
2009-09-16 08:37:16 +02:00
|
|
|
return WINED3D_OK;
|
|
|
|
}
|
2011-05-10 21:18:47 +02:00
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
HRESULT CDECL wined3d_volume_create(struct wined3d_device *device, UINT width, UINT height,
|
2013-08-22 14:57:54 +02:00
|
|
|
UINT depth, UINT level, DWORD usage, enum wined3d_format_id format_id, enum wined3d_pool pool,
|
|
|
|
void *parent, const struct wined3d_parent_ops *parent_ops, struct wined3d_volume **volume)
|
2011-05-10 21:18:47 +02:00
|
|
|
{
|
|
|
|
struct wined3d_volume *object;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
TRACE("device %p, width %u, height %u, depth %u, usage %#x, format %s, pool %s\n",
|
|
|
|
device, width, height, depth, usage, debug_d3dformat(format_id), debug_d3dpool(pool));
|
|
|
|
TRACE("parent %p, parent_ops %p, volume %p.\n", parent, parent_ops, volume);
|
|
|
|
|
|
|
|
object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
|
|
|
|
if (!object)
|
|
|
|
{
|
|
|
|
*volume = NULL;
|
|
|
|
return WINED3DERR_OUTOFVIDEOMEMORY;
|
|
|
|
}
|
|
|
|
|
2013-08-22 14:57:54 +02:00
|
|
|
hr = volume_init(object, device, width, height, depth, level,
|
|
|
|
usage, format_id, pool, parent, parent_ops);
|
2011-05-10 21:18:47 +02:00
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
|
|
|
WARN("Failed to initialize volume, returning %#x.\n", hr);
|
|
|
|
HeapFree(GetProcessHeap(), 0, object);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
TRACE("Created volume %p.\n", object);
|
|
|
|
*volume = object;
|
|
|
|
|
|
|
|
return WINED3D_OK;
|
|
|
|
}
|