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"
|
|
|
|
|
2016-03-29 16:45:35 +02:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(d3d);
|
2013-08-26 02:01:29 +02:00
|
|
|
WINE_DECLARE_DEBUG_CHANNEL(d3d_perf);
|
2010-05-24 09:56:36 +02:00
|
|
|
|
2015-04-16 11:26:33 +02:00
|
|
|
/* This call just uploads data, the caller is responsible for binding the
|
|
|
|
* correct texture. */
|
2013-08-22 14:57:55 +02:00
|
|
|
/* Context activation is done by the caller. */
|
2016-04-21 17:05:05 +02:00
|
|
|
void wined3d_volume_upload_data(struct wined3d_texture *texture, unsigned int sub_resource_idx,
|
|
|
|
const struct wined3d_context *context, const struct wined3d_const_bo_address *data)
|
2011-01-20 19:52:01 +01:00
|
|
|
{
|
2016-03-28 18:57:58 +02:00
|
|
|
const struct wined3d_format *format = texture->resource.format;
|
2016-04-21 17:05:05 +02:00
|
|
|
unsigned int level = sub_resource_idx % texture->level_count;
|
|
|
|
const struct wined3d_gl_info *gl_info = context->gl_info;
|
2016-04-13 19:09:51 +02:00
|
|
|
unsigned int width, height, depth;
|
2015-01-05 13:24:58 +01:00
|
|
|
const void *mem = data->addr;
|
|
|
|
void *converted_mem = NULL;
|
2011-01-20 19:52:01 +01:00
|
|
|
|
2016-04-21 17:05:05 +02:00
|
|
|
TRACE("texture %p, sub_resource_idx %u, context %p, format %s (%#x).\n",
|
|
|
|
texture, level, context, debug_d3dformat(format->id), format->id);
|
2011-01-20 19:52:01 +01:00
|
|
|
|
2016-04-21 17:05:05 +02:00
|
|
|
width = wined3d_texture_get_level_width(texture, level);
|
|
|
|
height = wined3d_texture_get_level_height(texture, level);
|
|
|
|
depth = wined3d_texture_get_level_depth(texture, level);
|
2016-04-13 19:09:51 +02: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;
|
|
|
|
|
|
|
|
if (data->buffer_object)
|
2016-04-21 17:05:05 +02:00
|
|
|
ERR("Loading a converted texture from a PBO.\n");
|
2016-03-28 18:57:58 +02:00
|
|
|
if (texture->resource.format_flags & WINED3DFMT_FLAG_BLOCKS)
|
2013-09-23 13:29:12 +02:00
|
|
|
ERR("Converting a block-based format.\n");
|
|
|
|
|
|
|
|
dst_row_pitch = width * format->conv_byte_count;
|
|
|
|
dst_slice_pitch = dst_row_pitch * height;
|
|
|
|
|
2016-04-21 17:05:05 +02:00
|
|
|
wined3d_texture_get_pitch(texture, level, &src_row_pitch, &src_slice_pitch);
|
2013-09-23 13:29:12 +02:00
|
|
|
|
2015-01-05 13:24:58 +01:00
|
|
|
converted_mem = HeapAlloc(GetProcessHeap(), 0, dst_slice_pitch * depth);
|
|
|
|
format->convert(data->addr, converted_mem, src_row_pitch, src_slice_pitch,
|
2013-09-23 13:29:13 +02:00
|
|
|
dst_row_pitch, dst_slice_pitch, width, height, depth);
|
2015-01-05 13:24:58 +01:00
|
|
|
mem = converted_mem;
|
2013-09-23 13:29:12 +02:00
|
|
|
}
|
2013-08-22 14:57:56 +02:00
|
|
|
|
|
|
|
if (data->buffer_object)
|
|
|
|
{
|
2015-01-14 16:27:31 +01:00
|
|
|
GL_EXTCALL(glBindBuffer(GL_PIXEL_UNPACK_BUFFER, data->buffer_object));
|
|
|
|
checkGLcall("glBindBuffer");
|
2013-08-22 14:57:56 +02:00
|
|
|
}
|
|
|
|
|
2016-04-21 17:05:05 +02:00
|
|
|
GL_EXTCALL(glTexSubImage3D(GL_TEXTURE_3D, level, 0, 0, 0,
|
|
|
|
width, height, depth, format->glFormat, format->glType, mem));
|
2013-08-22 14:57:56 +02:00
|
|
|
checkGLcall("glTexSubImage3D");
|
|
|
|
|
|
|
|
if (data->buffer_object)
|
|
|
|
{
|
2015-01-14 16:27:31 +01:00
|
|
|
GL_EXTCALL(glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0));
|
|
|
|
checkGLcall("glBindBuffer");
|
2013-08-22 14:57:56 +02:00
|
|
|
}
|
2013-09-23 13:29:12 +02:00
|
|
|
|
2015-01-05 13:24:58 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, converted_mem);
|
2013-08-22 14:57:56 +02:00
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2016-03-28 18:57:59 +02:00
|
|
|
const struct wined3d_format *format = volume->container->resource.format;
|
2013-08-22 23:22:46 +02:00
|
|
|
const struct wined3d_gl_info *gl_info = context->gl_info;
|
|
|
|
|
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)
|
|
|
|
{
|
2015-01-14 16:27:31 +01:00
|
|
|
GL_EXTCALL(glBindBuffer(GL_PIXEL_PACK_BUFFER, data->buffer_object));
|
|
|
|
checkGLcall("glBindBuffer");
|
2013-08-08 16:42:29 +02:00
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
{
|
2015-01-14 16:27:31 +01:00
|
|
|
GL_EXTCALL(glBindBuffer(GL_PIXEL_PACK_BUFFER, 0));
|
|
|
|
checkGLcall("glBindBuffer");
|
2013-08-08 16:42:29 +02:00
|
|
|
}
|
|
|
|
|
2013-08-22 23:22:46 +02:00
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
{
|
2016-04-20 19:29:12 +02:00
|
|
|
struct wined3d_texture *texture = volume->container;
|
2013-08-26 02:01:29 +02:00
|
|
|
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;
|
2016-04-20 19:29:12 +02:00
|
|
|
if (!(data.addr = HeapAlloc(GetProcessHeap(), 0, texture->sub_resources[volume->texture_level].size)))
|
2013-08-26 02:01:29 +02:00
|
|
|
return;
|
|
|
|
|
2016-04-20 19:29:12 +02:00
|
|
|
wined3d_texture_bind_and_dirtify(texture, context, !dest_is_srgb);
|
2013-08-26 02:01:29 +02:00
|
|
|
wined3d_volume_download_data(volume, context, &data);
|
2016-04-20 19:29:12 +02:00
|
|
|
wined3d_texture_bind_and_dirtify(texture, context, dest_is_srgb);
|
2016-04-21 17:05:05 +02:00
|
|
|
wined3d_volume_upload_data(texture, volume->texture_level, context, wined3d_const_bo_address(&data));
|
2013-08-26 02:01:29 +02:00
|
|
|
|
|
|
|
HeapFree(GetProcessHeap(), 0, data.addr);
|
|
|
|
}
|
|
|
|
|
2013-08-22 14:57:59 +02:00
|
|
|
/* Context activation is done by the caller. */
|
2016-03-11 16:01:43 +01:00
|
|
|
BOOL wined3d_volume_load_location(struct wined3d_volume *volume,
|
2013-08-22 14:57:59 +02:00
|
|
|
struct wined3d_context *context, DWORD location)
|
|
|
|
{
|
2013-08-22 23:22:47 +02:00
|
|
|
DWORD required_access = volume_access_from_location(location);
|
2016-03-29 16:45:36 +02:00
|
|
|
unsigned int sub_resource_idx = volume->texture_level;
|
2016-03-02 19:24:18 +01:00
|
|
|
struct wined3d_texture *texture = volume->container;
|
2016-03-28 18:58:01 +02:00
|
|
|
struct wined3d_texture_sub_resource *sub_resource;
|
2013-08-22 23:22:47 +02:00
|
|
|
|
2016-03-29 16:45:36 +02:00
|
|
|
sub_resource = &texture->sub_resources[sub_resource_idx];
|
2013-08-22 14:57:59 +02:00
|
|
|
TRACE("Volume %p, loading %s, have %s.\n", volume, wined3d_debug_location(location),
|
2016-03-28 18:58:01 +02:00
|
|
|
wined3d_debug_location(sub_resource->locations));
|
2013-08-22 14:57:59 +02:00
|
|
|
|
2016-03-28 18:58:01 +02:00
|
|
|
if ((sub_resource->locations & location) == location)
|
2013-08-22 14:57:59 +02:00
|
|
|
{
|
|
|
|
TRACE("Location(s) already up to date.\n");
|
2016-03-08 15:51:16 +01:00
|
|
|
return TRUE;
|
2013-08-22 14:57:59 +02:00
|
|
|
}
|
|
|
|
|
2016-03-28 18:58:00 +02:00
|
|
|
if ((texture->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",
|
2016-03-28 18:58:00 +02:00
|
|
|
required_access, texture->resource.access_flags);
|
2016-03-08 15:51:16 +01:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2016-04-19 18:34:09 +02:00
|
|
|
if (!wined3d_texture_prepare_location(texture, sub_resource_idx, context, location))
|
2016-03-08 15:51:16 +01:00
|
|
|
return FALSE;
|
|
|
|
|
2016-03-28 18:58:01 +02:00
|
|
|
if (sub_resource->locations & WINED3D_LOCATION_DISCARDED)
|
2016-03-08 15:51:16 +01:00
|
|
|
{
|
|
|
|
TRACE("Volume previously discarded, nothing to do.\n");
|
2016-03-30 21:30:19 +02:00
|
|
|
wined3d_texture_validate_location(texture, sub_resource_idx, location);
|
|
|
|
wined3d_texture_invalidate_location(texture, sub_resource_idx, WINED3D_LOCATION_DISCARDED);
|
2016-03-08 15:51:16 +01:00
|
|
|
goto done;
|
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:
|
2016-03-28 18:58:01 +02:00
|
|
|
if (sub_resource->locations & WINED3D_LOCATION_SYSMEM)
|
2013-08-22 14:57:59 +02:00
|
|
|
{
|
2016-04-20 19:29:12 +02:00
|
|
|
struct wined3d_const_bo_address data = {0, texture->resource.heap_memory};
|
|
|
|
data.addr += sub_resource->offset;
|
2016-03-02 19:24:18 +01:00
|
|
|
wined3d_texture_bind_and_dirtify(texture, context,
|
2015-04-16 11:26:33 +02:00
|
|
|
location == WINED3D_LOCATION_TEXTURE_SRGB);
|
2016-04-21 17:05:05 +02:00
|
|
|
wined3d_volume_upload_data(texture, sub_resource_idx, context, &data);
|
2013-08-22 14:57:59 +02:00
|
|
|
}
|
2016-03-28 18:58:01 +02:00
|
|
|
else if (sub_resource->locations & WINED3D_LOCATION_BUFFER)
|
2013-08-08 16:42:29 +02:00
|
|
|
{
|
2016-03-28 18:58:01 +02:00
|
|
|
struct wined3d_const_bo_address data = {sub_resource->buffer_object, NULL};
|
2016-03-02 19:24:18 +01:00
|
|
|
wined3d_texture_bind_and_dirtify(texture, context,
|
2015-04-16 11:26:33 +02:00
|
|
|
location == WINED3D_LOCATION_TEXTURE_SRGB);
|
2016-04-21 17:05:05 +02:00
|
|
|
wined3d_volume_upload_data(texture, sub_resource_idx, context, &data);
|
2013-08-08 16:42:29 +02:00
|
|
|
}
|
2016-03-28 18:58:01 +02:00
|
|
|
else if (sub_resource->locations & WINED3D_LOCATION_TEXTURE_RGB)
|
2013-08-26 02:01:29 +02:00
|
|
|
{
|
|
|
|
wined3d_volume_srgb_transfer(volume, context, TRUE);
|
|
|
|
}
|
2016-03-28 18:58:01 +02:00
|
|
|
else if (sub_resource->locations & WINED3D_LOCATION_TEXTURE_SRGB)
|
2013-08-26 02:01:29 +02:00
|
|
|
{
|
|
|
|
wined3d_volume_srgb_transfer(volume, context, FALSE);
|
|
|
|
}
|
2013-08-22 14:57:59 +02:00
|
|
|
else
|
|
|
|
{
|
2016-03-28 18:58:01 +02:00
|
|
|
FIXME("Implement texture loading from %s.\n", wined3d_debug_location(sub_resource->locations));
|
2016-03-08 15:51:16 +01:00
|
|
|
return FALSE;
|
2013-08-22 14:57:59 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WINED3D_LOCATION_SYSMEM:
|
2016-03-28 18:58:01 +02:00
|
|
|
if (sub_resource->locations & (WINED3D_LOCATION_TEXTURE_RGB | WINED3D_LOCATION_TEXTURE_SRGB))
|
2013-08-22 23:22:46 +02:00
|
|
|
{
|
2016-04-20 19:29:12 +02:00
|
|
|
struct wined3d_bo_address data = {0, texture->resource.heap_memory};
|
2013-08-26 02:01:29 +02:00
|
|
|
|
2016-04-20 19:29:12 +02:00
|
|
|
data.addr += sub_resource->offset;
|
2016-03-28 18:58:01 +02:00
|
|
|
if (sub_resource->locations & WINED3D_LOCATION_TEXTURE_RGB)
|
2016-03-02 19:24:18 +01:00
|
|
|
wined3d_texture_bind_and_dirtify(texture, context, FALSE);
|
2013-08-26 02:01:29 +02:00
|
|
|
else
|
2016-03-02 19:24:18 +01:00
|
|
|
wined3d_texture_bind_and_dirtify(texture, context, TRUE);
|
2013-08-26 02:01:29 +02:00
|
|
|
|
2013-08-08 16:42:29 +02:00
|
|
|
wined3d_volume_download_data(volume, context, &data);
|
2016-03-09 16:21:53 +01:00
|
|
|
++texture->download_count;
|
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",
|
2016-03-28 18:58:01 +02:00
|
|
|
wined3d_debug_location(sub_resource->locations));
|
2016-03-08 15:51:16 +01:00
|
|
|
return FALSE;
|
2013-08-22 14:57:59 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2013-08-08 16:42:29 +02:00
|
|
|
case WINED3D_LOCATION_BUFFER:
|
2016-03-28 18:58:01 +02:00
|
|
|
if (sub_resource->locations & (WINED3D_LOCATION_TEXTURE_RGB | WINED3D_LOCATION_TEXTURE_SRGB))
|
2013-08-08 16:42:29 +02:00
|
|
|
{
|
2016-03-28 18:58:01 +02:00
|
|
|
struct wined3d_bo_address data = {sub_resource->buffer_object, NULL};
|
2013-08-26 02:01:29 +02:00
|
|
|
|
2016-03-28 18:58:01 +02:00
|
|
|
if (sub_resource->locations & WINED3D_LOCATION_TEXTURE_RGB)
|
2016-03-02 19:24:18 +01:00
|
|
|
wined3d_texture_bind_and_dirtify(texture, context, FALSE);
|
2013-08-26 02:01:29 +02:00
|
|
|
else
|
2016-03-02 19:24:18 +01:00
|
|
|
wined3d_texture_bind_and_dirtify(texture, context, TRUE);
|
2013-08-26 02:01:29 +02:00
|
|
|
|
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",
|
2016-03-28 18:58:01 +02:00
|
|
|
wined3d_debug_location(sub_resource->locations));
|
2016-03-08 15:51:16 +01:00
|
|
|
return FALSE;
|
2013-08-08 16:42:29 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2013-08-22 14:57:59 +02:00
|
|
|
default:
|
|
|
|
FIXME("Implement %s loading from %s.\n", wined3d_debug_location(location),
|
2016-03-28 18:58:01 +02:00
|
|
|
wined3d_debug_location(sub_resource->locations));
|
2016-03-08 15:51:16 +01:00
|
|
|
return FALSE;
|
2013-08-22 14:57:59 +02:00
|
|
|
}
|
2016-03-08 15:51:16 +01:00
|
|
|
|
|
|
|
done:
|
2016-03-29 16:45:36 +02:00
|
|
|
wined3d_texture_validate_location(texture, sub_resource_idx, location);
|
2016-03-08 15:51:16 +01:00
|
|
|
|
|
|
|
return TRUE;
|
2013-08-22 14:57:59 +02:00
|
|
|
}
|