2005-01-09 18:37:02 +01:00
|
|
|
/*
|
2011-04-15 18:33:39 +02:00
|
|
|
* Copyright 1997-2000 Marcus Meissner
|
|
|
|
* Copyright 1998-2000 Lionel Ulmer
|
2006-05-06 18:08:33 +02:00
|
|
|
* Copyright 2000-2001 TransGaming Technologies Inc.
|
2005-01-09 18:37:02 +01:00
|
|
|
* Copyright 2002-2005 Jason Edmeades
|
|
|
|
* Copyright 2002-2003 Raphael Junqueira
|
|
|
|
* Copyright 2004 Christian Costa
|
2005-07-13 16:15:54 +02:00
|
|
|
* Copyright 2005 Oliver Stieber
|
2014-01-07 22:12:15 +01:00
|
|
|
* Copyright 2006-2011, 2013-2014 Stefan Dösinger for CodeWeavers
|
2008-08-19 17:49:07 +02:00
|
|
|
* Copyright 2007-2008 Henri Verbeet
|
2008-02-10 22:20:15 +01:00
|
|
|
* Copyright 2006-2008 Roderick Colenbrander
|
2011-04-05 19:01:29 +02:00
|
|
|
* Copyright 2009-2011 Henri Verbeet for CodeWeavers
|
2005-01-09 18:37:02 +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-09 18:37:02 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
2005-08-03 23:17:08 +02:00
|
|
|
#include "wine/port.h"
|
2005-01-09 18:37:02 +01:00
|
|
|
#include "wined3d_private.h"
|
|
|
|
|
2016-03-29 16:45:35 +02:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(d3d);
|
2013-04-17 08:47:59 +02:00
|
|
|
WINE_DECLARE_DEBUG_CHANNEL(d3d_perf);
|
2009-06-15 09:06:49 +02:00
|
|
|
|
2020-06-16 15:38:46 +02:00
|
|
|
static const DWORD surface_simple_locations = WINED3D_LOCATION_SYSMEM | WINED3D_LOCATION_BUFFER;
|
2014-01-15 14:54:09 +01:00
|
|
|
|
2012-08-15 00:38:25 +02:00
|
|
|
/* Works correctly only for <= 4 bpp formats. */
|
2021-06-07 16:55:08 +02:00
|
|
|
static void get_color_masks(const struct wined3d_format *format, uint32_t *masks)
|
2012-08-15 00:38:25 +02:00
|
|
|
{
|
2021-06-07 16:55:08 +02:00
|
|
|
masks[0] = wined3d_mask_from_size(format->red_size) << format->red_offset;
|
|
|
|
masks[1] = wined3d_mask_from_size(format->green_size) << format->green_offset;
|
|
|
|
masks[2] = wined3d_mask_from_size(format->blue_size) << format->blue_offset;
|
2012-08-15 00:38:25 +02:00
|
|
|
}
|
|
|
|
|
2011-04-25 22:54:13 +02:00
|
|
|
/* See also float_16_to_32() in wined3d_private.h */
|
|
|
|
static inline unsigned short float_32_to_16(const float *in)
|
|
|
|
{
|
|
|
|
int exp = 0;
|
2011-05-12 18:05:27 +02:00
|
|
|
float tmp = fabsf(*in);
|
2011-04-25 22:54:13 +02:00
|
|
|
unsigned int mantissa;
|
|
|
|
unsigned short ret;
|
|
|
|
|
|
|
|
/* Deal with special numbers */
|
|
|
|
if (*in == 0.0f)
|
|
|
|
return 0x0000;
|
|
|
|
if (isnan(*in))
|
|
|
|
return 0x7c01;
|
|
|
|
if (isinf(*in))
|
|
|
|
return (*in < 0.0f ? 0xfc00 : 0x7c00);
|
|
|
|
|
2015-08-26 12:46:46 +02:00
|
|
|
if (tmp < (float)(1u << 10))
|
2011-04-25 22:54:13 +02:00
|
|
|
{
|
|
|
|
do
|
|
|
|
{
|
|
|
|
tmp = tmp * 2.0f;
|
|
|
|
exp--;
|
2015-08-26 12:46:46 +02:00
|
|
|
} while (tmp < (float)(1u << 10));
|
2011-04-25 22:54:13 +02:00
|
|
|
}
|
2015-08-26 12:46:46 +02:00
|
|
|
else if (tmp >= (float)(1u << 11))
|
2011-04-25 22:54:13 +02:00
|
|
|
{
|
|
|
|
do
|
|
|
|
{
|
|
|
|
tmp /= 2.0f;
|
|
|
|
exp++;
|
2015-08-26 12:46:46 +02:00
|
|
|
} while (tmp >= (float)(1u << 11));
|
2011-04-25 22:54:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
mantissa = (unsigned int)tmp;
|
|
|
|
if (tmp - mantissa >= 0.5f)
|
|
|
|
++mantissa; /* Round to nearest, away from zero. */
|
|
|
|
|
|
|
|
exp += 10; /* Normalize the mantissa. */
|
|
|
|
exp += 15; /* Exponent is encoded with excess 15. */
|
|
|
|
|
|
|
|
if (exp > 30) /* too big */
|
|
|
|
{
|
|
|
|
ret = 0x7c00; /* INF */
|
|
|
|
}
|
|
|
|
else if (exp <= 0)
|
|
|
|
{
|
|
|
|
/* exp == 0: Non-normalized mantissa. Returns 0x0000 (=0.0) for too small numbers. */
|
|
|
|
while (exp <= 0)
|
|
|
|
{
|
|
|
|
mantissa = mantissa >> 1;
|
|
|
|
++exp;
|
|
|
|
}
|
|
|
|
ret = mantissa & 0x3ff;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ret = (exp << 10) | (mantissa & 0x3ff);
|
|
|
|
}
|
|
|
|
|
|
|
|
ret |= ((*in < 0.0f ? 1 : 0) << 15); /* Add the sign */
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void convert_r32_float_r16_float(const BYTE *src, BYTE *dst,
|
|
|
|
DWORD pitch_in, DWORD pitch_out, unsigned int w, unsigned int h)
|
|
|
|
{
|
|
|
|
unsigned short *dst_s;
|
|
|
|
const float *src_f;
|
|
|
|
unsigned int x, y;
|
|
|
|
|
|
|
|
TRACE("Converting %ux%u pixels, pitches %u %u.\n", w, h, pitch_in, pitch_out);
|
|
|
|
|
|
|
|
for (y = 0; y < h; ++y)
|
|
|
|
{
|
|
|
|
src_f = (const float *)(src + y * pitch_in);
|
|
|
|
dst_s = (unsigned short *) (dst + y * pitch_out);
|
|
|
|
for (x = 0; x < w; ++x)
|
|
|
|
{
|
|
|
|
dst_s[x] = float_32_to_16(src_f + x);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void convert_r5g6b5_x8r8g8b8(const BYTE *src, BYTE *dst,
|
|
|
|
DWORD pitch_in, DWORD pitch_out, unsigned int w, unsigned int h)
|
|
|
|
{
|
|
|
|
static const unsigned char convert_5to8[] =
|
|
|
|
{
|
|
|
|
0x00, 0x08, 0x10, 0x19, 0x21, 0x29, 0x31, 0x3a,
|
|
|
|
0x42, 0x4a, 0x52, 0x5a, 0x63, 0x6b, 0x73, 0x7b,
|
|
|
|
0x84, 0x8c, 0x94, 0x9c, 0xa5, 0xad, 0xb5, 0xbd,
|
|
|
|
0xc5, 0xce, 0xd6, 0xde, 0xe6, 0xef, 0xf7, 0xff,
|
|
|
|
};
|
|
|
|
static const unsigned char convert_6to8[] =
|
|
|
|
{
|
|
|
|
0x00, 0x04, 0x08, 0x0c, 0x10, 0x14, 0x18, 0x1c,
|
|
|
|
0x20, 0x24, 0x28, 0x2d, 0x31, 0x35, 0x39, 0x3d,
|
|
|
|
0x41, 0x45, 0x49, 0x4d, 0x51, 0x55, 0x59, 0x5d,
|
|
|
|
0x61, 0x65, 0x69, 0x6d, 0x71, 0x75, 0x79, 0x7d,
|
|
|
|
0x82, 0x86, 0x8a, 0x8e, 0x92, 0x96, 0x9a, 0x9e,
|
|
|
|
0xa2, 0xa6, 0xaa, 0xae, 0xb2, 0xb6, 0xba, 0xbe,
|
|
|
|
0xc2, 0xc6, 0xca, 0xce, 0xd2, 0xd7, 0xdb, 0xdf,
|
|
|
|
0xe3, 0xe7, 0xeb, 0xef, 0xf3, 0xf7, 0xfb, 0xff,
|
|
|
|
};
|
|
|
|
unsigned int x, y;
|
|
|
|
|
|
|
|
TRACE("Converting %ux%u pixels, pitches %u %u.\n", w, h, pitch_in, pitch_out);
|
|
|
|
|
|
|
|
for (y = 0; y < h; ++y)
|
|
|
|
{
|
|
|
|
const WORD *src_line = (const WORD *)(src + y * pitch_in);
|
|
|
|
DWORD *dst_line = (DWORD *)(dst + y * pitch_out);
|
|
|
|
for (x = 0; x < w; ++x)
|
|
|
|
{
|
|
|
|
WORD pixel = src_line[x];
|
2015-08-26 12:46:47 +02:00
|
|
|
dst_line[x] = 0xff000000u
|
|
|
|
| convert_5to8[(pixel & 0xf800u) >> 11] << 16
|
|
|
|
| convert_6to8[(pixel & 0x07e0u) >> 5] << 8
|
|
|
|
| convert_5to8[(pixel & 0x001fu)];
|
2011-04-25 22:54:13 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-08-21 21:34:52 +02:00
|
|
|
/* We use this for both B8G8R8A8 -> B8G8R8X8 and B8G8R8X8 -> B8G8R8A8, since
|
|
|
|
* in both cases we're just setting the X / Alpha channel to 0xff. */
|
2011-04-25 22:54:13 +02:00
|
|
|
static void convert_a8r8g8b8_x8r8g8b8(const BYTE *src, BYTE *dst,
|
|
|
|
DWORD pitch_in, DWORD pitch_out, unsigned int w, unsigned int h)
|
|
|
|
{
|
|
|
|
unsigned int x, y;
|
|
|
|
|
|
|
|
TRACE("Converting %ux%u pixels, pitches %u %u.\n", w, h, pitch_in, pitch_out);
|
|
|
|
|
|
|
|
for (y = 0; y < h; ++y)
|
|
|
|
{
|
|
|
|
const DWORD *src_line = (const DWORD *)(src + y * pitch_in);
|
|
|
|
DWORD *dst_line = (DWORD *)(dst + y * pitch_out);
|
|
|
|
|
|
|
|
for (x = 0; x < w; ++x)
|
|
|
|
{
|
|
|
|
dst_line[x] = 0xff000000 | (src_line[x] & 0xffffff);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline BYTE cliptobyte(int x)
|
|
|
|
{
|
|
|
|
return (BYTE)((x < 0) ? 0 : ((x > 255) ? 255 : x));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void convert_yuy2_x8r8g8b8(const BYTE *src, BYTE *dst,
|
|
|
|
DWORD pitch_in, DWORD pitch_out, unsigned int w, unsigned int h)
|
|
|
|
{
|
|
|
|
int c2, d, e, r2 = 0, g2 = 0, b2 = 0;
|
|
|
|
unsigned int x, y;
|
|
|
|
|
|
|
|
TRACE("Converting %ux%u pixels, pitches %u %u.\n", w, h, pitch_in, pitch_out);
|
|
|
|
|
|
|
|
for (y = 0; y < h; ++y)
|
|
|
|
{
|
|
|
|
const BYTE *src_line = src + y * pitch_in;
|
|
|
|
DWORD *dst_line = (DWORD *)(dst + y * pitch_out);
|
|
|
|
for (x = 0; x < w; ++x)
|
|
|
|
{
|
|
|
|
/* YUV to RGB conversion formulas from http://en.wikipedia.org/wiki/YUV:
|
|
|
|
* C = Y - 16; D = U - 128; E = V - 128;
|
|
|
|
* R = cliptobyte((298 * C + 409 * E + 128) >> 8);
|
|
|
|
* G = cliptobyte((298 * C - 100 * D - 208 * E + 128) >> 8);
|
|
|
|
* B = cliptobyte((298 * C + 516 * D + 128) >> 8);
|
|
|
|
* Two adjacent YUY2 pixels are stored as four bytes: Y0 U Y1 V .
|
|
|
|
* U and V are shared between the pixels. */
|
|
|
|
if (!(x & 1)) /* For every even pixel, read new U and V. */
|
|
|
|
{
|
|
|
|
d = (int) src_line[1] - 128;
|
|
|
|
e = (int) src_line[3] - 128;
|
|
|
|
r2 = 409 * e + 128;
|
|
|
|
g2 = - 100 * d - 208 * e + 128;
|
|
|
|
b2 = 516 * d + 128;
|
|
|
|
}
|
|
|
|
c2 = 298 * ((int) src_line[0] - 16);
|
|
|
|
dst_line[x] = 0xff000000
|
|
|
|
| cliptobyte((c2 + r2) >> 8) << 16 /* red */
|
|
|
|
| cliptobyte((c2 + g2) >> 8) << 8 /* green */
|
|
|
|
| cliptobyte((c2 + b2) >> 8); /* blue */
|
|
|
|
/* Scale RGB values to 0..255 range,
|
|
|
|
* then clip them if still not in range (may be negative),
|
|
|
|
* then shift them within DWORD if necessary. */
|
|
|
|
src_line += 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void convert_yuy2_r5g6b5(const BYTE *src, BYTE *dst,
|
|
|
|
DWORD pitch_in, DWORD pitch_out, unsigned int w, unsigned int h)
|
|
|
|
{
|
|
|
|
unsigned int x, y;
|
|
|
|
int c2, d, e, r2 = 0, g2 = 0, b2 = 0;
|
|
|
|
|
|
|
|
TRACE("Converting %ux%u pixels, pitches %u %u\n", w, h, pitch_in, pitch_out);
|
|
|
|
|
|
|
|
for (y = 0; y < h; ++y)
|
|
|
|
{
|
|
|
|
const BYTE *src_line = src + y * pitch_in;
|
|
|
|
WORD *dst_line = (WORD *)(dst + y * pitch_out);
|
|
|
|
for (x = 0; x < w; ++x)
|
|
|
|
{
|
|
|
|
/* YUV to RGB conversion formulas from http://en.wikipedia.org/wiki/YUV:
|
|
|
|
* C = Y - 16; D = U - 128; E = V - 128;
|
|
|
|
* R = cliptobyte((298 * C + 409 * E + 128) >> 8);
|
|
|
|
* G = cliptobyte((298 * C - 100 * D - 208 * E + 128) >> 8);
|
|
|
|
* B = cliptobyte((298 * C + 516 * D + 128) >> 8);
|
|
|
|
* Two adjacent YUY2 pixels are stored as four bytes: Y0 U Y1 V .
|
|
|
|
* U and V are shared between the pixels. */
|
|
|
|
if (!(x & 1)) /* For every even pixel, read new U and V. */
|
|
|
|
{
|
|
|
|
d = (int) src_line[1] - 128;
|
|
|
|
e = (int) src_line[3] - 128;
|
|
|
|
r2 = 409 * e + 128;
|
|
|
|
g2 = - 100 * d - 208 * e + 128;
|
|
|
|
b2 = 516 * d + 128;
|
|
|
|
}
|
|
|
|
c2 = 298 * ((int) src_line[0] - 16);
|
|
|
|
dst_line[x] = (cliptobyte((c2 + r2) >> 8) >> 3) << 11 /* red */
|
|
|
|
| (cliptobyte((c2 + g2) >> 8) >> 2) << 5 /* green */
|
|
|
|
| (cliptobyte((c2 + b2) >> 8) >> 3); /* blue */
|
|
|
|
/* Scale RGB values to 0..255 range,
|
|
|
|
* then clip them if still not in range (may be negative),
|
|
|
|
* then shift them within DWORD if necessary. */
|
|
|
|
src_line += 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-16 12:58:54 +02:00
|
|
|
struct d3dfmt_converter_desc
|
2011-04-25 22:54:13 +02:00
|
|
|
{
|
|
|
|
enum wined3d_format_id from, to;
|
|
|
|
void (*convert)(const BYTE *src, BYTE *dst, DWORD pitch_in, DWORD pitch_out, unsigned int w, unsigned int h);
|
|
|
|
};
|
|
|
|
|
2012-08-16 12:58:54 +02:00
|
|
|
static const struct d3dfmt_converter_desc converters[] =
|
2011-04-25 22:54:13 +02:00
|
|
|
{
|
|
|
|
{WINED3DFMT_R32_FLOAT, WINED3DFMT_R16_FLOAT, convert_r32_float_r16_float},
|
|
|
|
{WINED3DFMT_B5G6R5_UNORM, WINED3DFMT_B8G8R8X8_UNORM, convert_r5g6b5_x8r8g8b8},
|
|
|
|
{WINED3DFMT_B8G8R8A8_UNORM, WINED3DFMT_B8G8R8X8_UNORM, convert_a8r8g8b8_x8r8g8b8},
|
2011-08-21 21:34:52 +02:00
|
|
|
{WINED3DFMT_B8G8R8X8_UNORM, WINED3DFMT_B8G8R8A8_UNORM, convert_a8r8g8b8_x8r8g8b8},
|
2011-04-25 22:54:13 +02:00
|
|
|
{WINED3DFMT_YUY2, WINED3DFMT_B8G8R8X8_UNORM, convert_yuy2_x8r8g8b8},
|
|
|
|
{WINED3DFMT_YUY2, WINED3DFMT_B5G6R5_UNORM, convert_yuy2_r5g6b5},
|
|
|
|
};
|
|
|
|
|
2012-08-16 12:58:54 +02:00
|
|
|
static inline const struct d3dfmt_converter_desc *find_converter(enum wined3d_format_id from,
|
2011-04-25 22:54:13 +02:00
|
|
|
enum wined3d_format_id to)
|
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
|
2017-10-19 10:07:29 +02:00
|
|
|
for (i = 0; i < ARRAY_SIZE(converters); ++i)
|
2011-04-25 22:54:13 +02:00
|
|
|
{
|
2012-08-16 12:58:54 +02:00
|
|
|
if (converters[i].from == from && converters[i].to == to)
|
|
|
|
return &converters[i];
|
2011-04-25 22:54:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2016-03-07 17:05:53 +01:00
|
|
|
static struct wined3d_texture *surface_convert_format(struct wined3d_texture *src_texture,
|
2016-04-04 18:42:58 +02:00
|
|
|
unsigned int sub_resource_idx, const struct wined3d_format *dst_format)
|
2011-04-25 22:54:13 +02:00
|
|
|
{
|
2016-04-20 19:29:09 +02:00
|
|
|
unsigned int texture_level = sub_resource_idx % src_texture->level_count;
|
2016-04-04 18:42:58 +02:00
|
|
|
const struct wined3d_format *src_format = src_texture->resource.format;
|
|
|
|
struct wined3d_device *device = src_texture->resource.device;
|
|
|
|
const struct d3dfmt_converter_desc *conv = NULL;
|
2017-04-13 00:11:02 +02:00
|
|
|
unsigned int src_row_pitch, src_slice_pitch;
|
2016-03-07 17:05:53 +01:00
|
|
|
struct wined3d_texture *dst_texture;
|
2017-04-13 00:11:02 +02:00
|
|
|
struct wined3d_bo_address src_data;
|
2013-11-13 10:12:09 +01:00
|
|
|
struct wined3d_resource_desc desc;
|
2019-08-15 23:01:38 +02:00
|
|
|
struct wined3d_context *context;
|
2017-04-13 00:11:02 +02:00
|
|
|
DWORD map_binding;
|
2011-04-25 22:54:13 +02:00
|
|
|
|
2020-06-02 01:17:02 +02:00
|
|
|
if (!(conv = find_converter(src_format->id, dst_format->id)) && ((device->wined3d->flags & WINED3D_NO3D)
|
2018-01-05 18:53:12 +01:00
|
|
|
|| !is_identity_fixup(src_format->color_fixup) || src_format->conv_byte_count
|
|
|
|
|| !is_identity_fixup(dst_format->color_fixup) || dst_format->conv_byte_count
|
2019-11-08 12:57:23 +01:00
|
|
|
|| ((src_format->flags[WINED3D_GL_RES_TYPE_TEX_2D] & WINED3DFMT_FLAG_COMPRESSED)
|
|
|
|
&& !src_format->decompress)))
|
2011-04-25 22:54:13 +02:00
|
|
|
{
|
|
|
|
FIXME("Cannot find a conversion function from format %s to %s.\n",
|
2016-04-04 18:42:58 +02:00
|
|
|
debug_d3dformat(src_format->id), debug_d3dformat(dst_format->id));
|
2011-04-25 22:54:13 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2012-10-23 21:01:05 +02:00
|
|
|
/* FIXME: Multisampled conversion? */
|
2016-01-27 00:06:23 +01:00
|
|
|
desc.resource_type = WINED3D_RTYPE_TEXTURE_2D;
|
2016-04-04 18:42:58 +02:00
|
|
|
desc.format = dst_format->id;
|
2016-04-20 19:29:09 +02:00
|
|
|
desc.multisample_type = WINED3D_MULTISAMPLE_NONE;
|
|
|
|
desc.multisample_quality = 0;
|
2018-01-29 18:40:23 +01:00
|
|
|
desc.usage = WINED3DUSAGE_SCRATCH | WINED3DUSAGE_PRIVATE;
|
2018-10-31 10:31:47 +01:00
|
|
|
desc.bind_flags = 0;
|
2018-02-18 19:08:35 +01:00
|
|
|
desc.access = WINED3D_RESOURCE_ACCESS_CPU | WINED3D_RESOURCE_ACCESS_MAP_R | WINED3D_RESOURCE_ACCESS_MAP_W;
|
2016-04-20 19:29:09 +02:00
|
|
|
desc.width = wined3d_texture_get_level_width(src_texture, texture_level);
|
|
|
|
desc.height = wined3d_texture_get_level_height(src_texture, texture_level);
|
|
|
|
desc.depth = 1;
|
|
|
|
desc.size = 0;
|
2018-11-23 16:30:48 +01:00
|
|
|
if (FAILED(wined3d_texture_create(device, &desc, 1, 1, WINED3D_TEXTURE_CREATE_DISCARD,
|
2016-03-07 17:05:53 +01:00
|
|
|
NULL, NULL, &wined3d_null_parent_ops, &dst_texture)))
|
2011-04-25 22:54:13 +02:00
|
|
|
{
|
2016-03-07 17:05:53 +01:00
|
|
|
ERR("Failed to create a destination texture for conversion.\n");
|
2011-04-25 22:54:13 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2019-08-15 23:01:38 +02:00
|
|
|
context = context_acquire(device, NULL, 0);
|
2016-04-04 18:42:58 +02:00
|
|
|
|
2017-04-13 00:11:02 +02:00
|
|
|
map_binding = src_texture->resource.map_binding;
|
|
|
|
if (!wined3d_texture_load_location(src_texture, sub_resource_idx, context, map_binding))
|
|
|
|
ERR("Failed to load the source sub-resource into %s.\n", wined3d_debug_location(map_binding));
|
|
|
|
wined3d_texture_get_pitch(src_texture, texture_level, &src_row_pitch, &src_slice_pitch);
|
|
|
|
wined3d_texture_get_memory(src_texture, sub_resource_idx, &src_data, map_binding);
|
2016-04-04 18:42:58 +02:00
|
|
|
|
2017-04-13 00:11:02 +02:00
|
|
|
if (conv)
|
|
|
|
{
|
|
|
|
unsigned int dst_row_pitch, dst_slice_pitch;
|
|
|
|
struct wined3d_bo_address dst_data;
|
2020-02-27 13:31:10 +01:00
|
|
|
struct wined3d_range range;
|
2017-04-13 00:11:02 +02:00
|
|
|
const BYTE *src;
|
|
|
|
BYTE *dst;
|
|
|
|
|
|
|
|
map_binding = dst_texture->resource.map_binding;
|
|
|
|
if (!wined3d_texture_load_location(dst_texture, 0, context, map_binding))
|
|
|
|
ERR("Failed to load the destination sub-resource into %s.\n", wined3d_debug_location(map_binding));
|
|
|
|
wined3d_texture_get_pitch(dst_texture, 0, &dst_row_pitch, &dst_slice_pitch);
|
|
|
|
wined3d_texture_get_memory(dst_texture, 0, &dst_data, map_binding);
|
|
|
|
|
2019-08-15 23:01:38 +02:00
|
|
|
src = wined3d_context_map_bo_address(context, &src_data,
|
2020-04-22 15:12:46 +02:00
|
|
|
src_texture->sub_resources[sub_resource_idx].size, WINED3D_MAP_READ);
|
2019-08-15 23:01:38 +02:00
|
|
|
dst = wined3d_context_map_bo_address(context, &dst_data,
|
2020-04-22 15:12:46 +02:00
|
|
|
dst_texture->sub_resources[0].size, WINED3D_MAP_WRITE);
|
2017-04-13 00:11:02 +02:00
|
|
|
|
|
|
|
conv->convert(src, dst, src_row_pitch, dst_row_pitch, desc.width, desc.height);
|
|
|
|
|
2019-09-23 13:24:16 +02:00
|
|
|
range.offset = 0;
|
|
|
|
range.size = dst_texture->sub_resources[0].size;
|
2017-04-13 00:11:02 +02:00
|
|
|
wined3d_texture_invalidate_location(dst_texture, 0, ~map_binding);
|
2020-04-22 15:12:45 +02:00
|
|
|
wined3d_context_unmap_bo_address(context, &dst_data, 1, &range);
|
|
|
|
wined3d_context_unmap_bo_address(context, &src_data, 0, NULL);
|
2011-04-25 22:54:13 +02:00
|
|
|
}
|
2016-04-04 18:42:58 +02:00
|
|
|
else
|
|
|
|
{
|
2018-03-18 21:39:09 +01:00
|
|
|
struct wined3d_box src_box = {0, 0, desc.width, desc.height, 0, 1};
|
2016-04-04 18:42:58 +02:00
|
|
|
|
|
|
|
TRACE("Using upload conversion.\n");
|
2011-04-25 22:54:13 +02:00
|
|
|
|
2019-06-12 13:29:32 +02:00
|
|
|
wined3d_texture_prepare_location(dst_texture, 0, context, WINED3D_LOCATION_TEXTURE_RGB);
|
2019-06-12 13:29:35 +02:00
|
|
|
dst_texture->texture_ops->texture_upload_data(context, wined3d_const_bo_address(&src_data),
|
|
|
|
src_format, &src_box, src_row_pitch, src_slice_pitch,
|
|
|
|
dst_texture, 0, WINED3D_LOCATION_TEXTURE_RGB, 0, 0, 0);
|
2016-04-04 18:42:58 +02:00
|
|
|
|
|
|
|
wined3d_texture_validate_location(dst_texture, 0, WINED3D_LOCATION_TEXTURE_RGB);
|
|
|
|
wined3d_texture_invalidate_location(dst_texture, 0, ~WINED3D_LOCATION_TEXTURE_RGB);
|
|
|
|
}
|
2017-04-13 00:11:02 +02:00
|
|
|
|
2019-08-15 23:01:38 +02:00
|
|
|
context_release(context);
|
2011-04-25 22:54:13 +02:00
|
|
|
|
2016-03-07 17:05:53 +01:00
|
|
|
return dst_texture;
|
2011-04-25 22:54:13 +02:00
|
|
|
}
|
|
|
|
|
2019-06-17 12:32:14 +02:00
|
|
|
void texture2d_read_from_framebuffer(struct wined3d_texture *texture, unsigned int sub_resource_idx,
|
2018-03-08 08:05:02 +01:00
|
|
|
struct wined3d_context *context, DWORD src_location, DWORD dst_location)
|
2009-12-09 20:32:08 +01:00
|
|
|
{
|
2018-09-22 01:26:09 +02:00
|
|
|
struct wined3d_resource *resource = &texture->resource;
|
|
|
|
struct wined3d_device *device = resource->device;
|
|
|
|
const struct wined3d_format_gl *format_gl;
|
2018-03-08 08:05:02 +01:00
|
|
|
struct wined3d_texture *restore_texture;
|
2018-02-22 16:43:13 +01:00
|
|
|
const struct wined3d_gl_info *gl_info;
|
2019-05-15 15:32:54 +02:00
|
|
|
struct wined3d_context_gl *context_gl;
|
2016-02-12 11:06:05 +01:00
|
|
|
unsigned int row_pitch, slice_pitch;
|
2018-02-28 07:26:56 +01:00
|
|
|
unsigned int width, height, level;
|
2018-02-22 16:43:13 +01:00
|
|
|
struct wined3d_bo_address data;
|
2018-03-08 08:05:02 +01:00
|
|
|
unsigned int restore_idx;
|
2007-02-13 20:24:00 +01:00
|
|
|
BYTE *row, *top, *bottom;
|
2018-02-22 16:43:13 +01:00
|
|
|
BOOL src_is_upside_down;
|
|
|
|
unsigned int i;
|
|
|
|
BYTE *mem;
|
2013-11-29 12:59:13 +01:00
|
|
|
|
2016-03-31 22:48:54 +02:00
|
|
|
wined3d_texture_get_memory(texture, sub_resource_idx, &data, dst_location);
|
2007-11-02 22:23:22 +01:00
|
|
|
|
2018-03-08 08:05:02 +01:00
|
|
|
restore_texture = context->current_rt.texture;
|
|
|
|
restore_idx = context->current_rt.sub_resource_idx;
|
|
|
|
if (restore_texture != texture || restore_idx != sub_resource_idx)
|
2017-02-15 14:17:15 +01:00
|
|
|
context = context_acquire(device, texture, sub_resource_idx);
|
2016-03-29 16:45:32 +02:00
|
|
|
else
|
2018-03-08 08:05:02 +01:00
|
|
|
restore_texture = NULL;
|
2019-05-15 15:32:54 +02:00
|
|
|
context_gl = wined3d_context_gl(context);
|
2019-08-07 13:41:58 +02:00
|
|
|
gl_info = context_gl->gl_info;
|
2010-03-17 21:59:50 +01:00
|
|
|
|
2018-09-22 01:26:09 +02:00
|
|
|
if (src_location != resource->draw_binding)
|
2018-02-22 16:43:13 +01:00
|
|
|
{
|
2019-05-15 15:32:54 +02:00
|
|
|
wined3d_context_gl_apply_fbo_state_blit(context_gl, GL_READ_FRAMEBUFFER,
|
2018-09-22 01:26:09 +02:00
|
|
|
resource, sub_resource_idx, NULL, 0, src_location);
|
2019-05-15 15:32:55 +02:00
|
|
|
wined3d_context_gl_check_fbo_status(context_gl, GL_READ_FRAMEBUFFER);
|
2018-02-22 16:43:13 +01:00
|
|
|
context_invalidate_state(context, STATE_FRAMEBUFFER);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-05-15 15:32:54 +02:00
|
|
|
wined3d_context_gl_apply_blit_state(context_gl, device);
|
2018-02-22 16:43:13 +01:00
|
|
|
}
|
|
|
|
|
2007-11-02 22:23:22 +01:00
|
|
|
/* Select the correct read buffer, and give some debug output.
|
2018-02-22 16:43:13 +01:00
|
|
|
* There is no need to keep track of the current read buffer or reset it,
|
|
|
|
* every part of the code that reads sets the read buffer as desired.
|
2007-11-02 22:23:22 +01:00
|
|
|
*/
|
2018-09-22 01:26:09 +02:00
|
|
|
if (src_location != WINED3D_LOCATION_DRAWABLE || wined3d_resource_is_offscreen(resource))
|
2008-10-16 11:52:54 +02:00
|
|
|
{
|
2010-10-14 13:04:02 +02:00
|
|
|
/* Mapping the primary render target which is not on a swapchain.
|
|
|
|
* Read from the back buffer. */
|
|
|
|
TRACE("Mapping offscreen render target.\n");
|
2019-05-19 16:00:44 +02:00
|
|
|
gl_info->gl_ops.gl.p_glReadBuffer(wined3d_context_gl_get_offscreen_gl_buffer(context_gl));
|
2018-02-22 16:43:13 +01:00
|
|
|
src_is_upside_down = TRUE;
|
2007-11-02 22:23:22 +01:00
|
|
|
}
|
2009-12-06 15:45:46 +01:00
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Onscreen surfaces are always part of a swapchain */
|
2016-03-23 17:58:23 +01:00
|
|
|
GLenum buffer = wined3d_texture_get_gl_buffer(texture);
|
2010-10-14 13:04:02 +02:00
|
|
|
TRACE("Mapping %#x buffer.\n", buffer);
|
2012-07-24 11:32:27 +02:00
|
|
|
gl_info->gl_ops.gl.p_glReadBuffer(buffer);
|
2018-02-22 16:43:13 +01:00
|
|
|
src_is_upside_down = FALSE;
|
2009-12-06 15:45:46 +01:00
|
|
|
}
|
2018-02-22 16:43:13 +01:00
|
|
|
checkGLcall("glReadBuffer");
|
2007-11-02 22:23:22 +01:00
|
|
|
|
2013-11-29 12:59:13 +01:00
|
|
|
if (data.buffer_object)
|
2010-11-12 13:12:04 +01:00
|
|
|
{
|
2020-04-21 20:07:09 +02:00
|
|
|
GL_EXTCALL(glBindBuffer(GL_PIXEL_PACK_BUFFER, ((struct wined3d_bo_gl *)data.buffer_object)->id));
|
2015-01-14 16:27:31 +01:00
|
|
|
checkGLcall("glBindBuffer");
|
2007-09-11 10:31:54 +02:00
|
|
|
}
|
|
|
|
|
2018-02-28 07:26:56 +01:00
|
|
|
level = sub_resource_idx % texture->level_count;
|
|
|
|
wined3d_texture_get_pitch(texture, level, &row_pitch, &slice_pitch);
|
2018-09-22 01:26:09 +02:00
|
|
|
format_gl = wined3d_format_gl(resource->format);
|
2016-02-12 11:06:05 +01:00
|
|
|
|
2008-12-22 15:08:10 +01:00
|
|
|
/* Setup pixel store pack state -- to glReadPixels into the correct place */
|
2018-09-22 01:26:09 +02:00
|
|
|
gl_info->gl_ops.gl.p_glPixelStorei(GL_PACK_ROW_LENGTH, row_pitch / format_gl->f.byte_count);
|
2008-12-22 15:08:10 +01:00
|
|
|
checkGLcall("glPixelStorei");
|
|
|
|
|
2018-02-28 07:26:56 +01:00
|
|
|
width = wined3d_texture_get_level_width(texture, level);
|
|
|
|
height = wined3d_texture_get_level_height(texture, level);
|
2016-04-05 18:24:22 +02:00
|
|
|
gl_info->gl_ops.gl.p_glReadPixels(0, 0, width, height,
|
2018-09-22 01:26:09 +02:00
|
|
|
format_gl->format, format_gl->type, data.addr);
|
2008-12-03 14:53:44 +01:00
|
|
|
checkGLcall("glReadPixels");
|
2007-02-13 20:24:00 +01:00
|
|
|
|
2008-12-22 15:08:10 +01:00
|
|
|
/* Reset previous pixel store pack state */
|
2013-11-29 12:59:14 +01:00
|
|
|
gl_info->gl_ops.gl.p_glPixelStorei(GL_PACK_ROW_LENGTH, 0);
|
2008-12-22 15:08:10 +01:00
|
|
|
checkGLcall("glPixelStorei");
|
|
|
|
|
2018-02-22 16:43:13 +01:00
|
|
|
if (!src_is_upside_down)
|
2013-11-20 12:33:31 +01:00
|
|
|
{
|
2016-02-12 11:06:05 +01:00
|
|
|
/* glReadPixels returns the image upside down, and there is no way to
|
|
|
|
* prevent this. Flip the lines in software. */
|
2014-05-13 16:21:49 +02:00
|
|
|
|
2018-02-14 07:39:59 +01:00
|
|
|
if (!(row = heap_alloc(row_pitch)))
|
2014-05-13 16:21:49 +02:00
|
|
|
goto error;
|
2007-02-13 20:24:00 +01:00
|
|
|
|
2014-05-13 16:21:49 +02:00
|
|
|
if (data.buffer_object)
|
2013-11-20 12:33:31 +01:00
|
|
|
{
|
2015-01-14 16:27:31 +01:00
|
|
|
mem = GL_EXTCALL(glMapBuffer(GL_PIXEL_PACK_BUFFER, GL_READ_WRITE));
|
|
|
|
checkGLcall("glMapBuffer");
|
2006-07-17 12:39:44 +02:00
|
|
|
}
|
2014-05-13 16:21:49 +02:00
|
|
|
else
|
|
|
|
mem = data.addr;
|
2007-02-13 20:24:00 +01:00
|
|
|
|
2013-11-20 12:33:31 +01:00
|
|
|
top = mem;
|
2016-04-05 18:24:22 +02:00
|
|
|
bottom = mem + row_pitch * (height - 1);
|
|
|
|
for (i = 0; i < height / 2; i++)
|
2013-11-20 12:33:31 +01:00
|
|
|
{
|
2016-02-12 11:06:05 +01:00
|
|
|
memcpy(row, top, row_pitch);
|
|
|
|
memcpy(top, bottom, row_pitch);
|
|
|
|
memcpy(bottom, row, row_pitch);
|
|
|
|
top += row_pitch;
|
|
|
|
bottom -= row_pitch;
|
2006-07-17 12:39:44 +02:00
|
|
|
}
|
2018-02-14 07:39:59 +01:00
|
|
|
heap_free(row);
|
2014-05-13 16:21:49 +02:00
|
|
|
|
|
|
|
if (data.buffer_object)
|
2015-01-14 16:27:31 +01:00
|
|
|
GL_EXTCALL(glUnmapBuffer(GL_PIXEL_PACK_BUFFER));
|
2013-11-29 12:59:13 +01:00
|
|
|
}
|
2007-09-11 10:31:54 +02:00
|
|
|
|
2014-05-13 16:21:49 +02:00
|
|
|
error:
|
2013-11-29 12:59:13 +01:00
|
|
|
if (data.buffer_object)
|
|
|
|
{
|
2015-01-14 16:27:31 +01:00
|
|
|
GL_EXTCALL(glBindBuffer(GL_PIXEL_PACK_BUFFER, 0));
|
2020-12-02 17:30:00 +01:00
|
|
|
wined3d_context_gl_reference_bo(context_gl, (struct wined3d_bo_gl *)data.buffer_object);
|
2015-01-14 16:27:31 +01:00
|
|
|
checkGLcall("glBindBuffer");
|
2006-07-17 12:39:44 +02:00
|
|
|
}
|
|
|
|
|
2018-03-08 08:05:02 +01:00
|
|
|
if (restore_texture)
|
2018-03-12 10:06:47 +01:00
|
|
|
context_restore(context, restore_texture, restore_idx);
|
2006-07-17 12:39:44 +02:00
|
|
|
}
|
|
|
|
|
2011-11-03 19:37:24 +01:00
|
|
|
/* Read the framebuffer contents into a texture. Note that this function
|
|
|
|
* doesn't do any kind of flipping. Using this on an onscreen surface will
|
2015-10-15 22:41:11 +02:00
|
|
|
* result in a flipped D3D texture.
|
|
|
|
*
|
|
|
|
* Context activation is done by the caller. This function may temporarily
|
|
|
|
* switch to a different context and restore the original one before return. */
|
2018-10-30 10:48:44 +01:00
|
|
|
void texture2d_load_fb_texture(struct wined3d_texture_gl *texture_gl,
|
2018-03-09 07:31:51 +01:00
|
|
|
unsigned int sub_resource_idx, BOOL srgb, struct wined3d_context *context)
|
2008-02-10 22:20:15 +01:00
|
|
|
{
|
2018-03-09 07:31:51 +01:00
|
|
|
struct wined3d_texture *restore_texture;
|
2012-07-24 11:32:27 +02:00
|
|
|
const struct wined3d_gl_info *gl_info;
|
2019-05-19 16:00:44 +02:00
|
|
|
struct wined3d_context_gl *context_gl;
|
2018-10-30 10:48:44 +01:00
|
|
|
struct wined3d_resource *resource;
|
2018-03-09 07:31:51 +01:00
|
|
|
unsigned int restore_idx, level;
|
2018-10-30 10:48:44 +01:00
|
|
|
struct wined3d_device *device;
|
2018-02-22 08:06:57 +01:00
|
|
|
GLenum target;
|
2015-10-15 22:41:11 +02:00
|
|
|
|
2018-10-30 10:48:44 +01:00
|
|
|
resource = &texture_gl->t.resource;
|
|
|
|
device = resource->device;
|
2018-03-09 07:31:51 +01:00
|
|
|
restore_texture = context->current_rt.texture;
|
|
|
|
restore_idx = context->current_rt.sub_resource_idx;
|
2018-10-30 10:48:44 +01:00
|
|
|
if (restore_texture != &texture_gl->t || restore_idx != sub_resource_idx)
|
|
|
|
context = context_acquire(device, &texture_gl->t, sub_resource_idx);
|
2016-03-29 16:45:32 +02:00
|
|
|
else
|
2018-03-09 07:31:51 +01:00
|
|
|
restore_texture = NULL;
|
2019-05-19 16:00:44 +02:00
|
|
|
context_gl = wined3d_context_gl(context);
|
2008-02-10 22:20:15 +01:00
|
|
|
|
2019-08-07 13:41:58 +02:00
|
|
|
gl_info = context_gl->gl_info;
|
2011-06-08 00:27:15 +02:00
|
|
|
device_invalidate_state(device, STATE_FRAMEBUFFER);
|
2010-03-17 21:59:50 +01:00
|
|
|
|
2019-06-12 13:29:32 +02:00
|
|
|
wined3d_texture_gl_prepare_texture(texture_gl, context_gl, srgb);
|
2019-05-19 16:00:44 +02:00
|
|
|
wined3d_texture_gl_bind_and_dirtify(texture_gl, context_gl, srgb);
|
2008-02-10 22:20:15 +01:00
|
|
|
|
2018-10-30 10:48:44 +01:00
|
|
|
TRACE("Reading back offscreen render target %p, %u.\n", texture_gl, sub_resource_idx);
|
2008-02-10 22:20:15 +01:00
|
|
|
|
2018-10-30 10:48:44 +01:00
|
|
|
if (wined3d_resource_is_offscreen(resource))
|
2019-05-19 16:00:44 +02:00
|
|
|
gl_info->gl_ops.gl.p_glReadBuffer(wined3d_context_gl_get_offscreen_gl_buffer(context_gl));
|
2011-11-03 19:37:24 +01:00
|
|
|
else
|
2018-10-30 10:48:44 +01:00
|
|
|
gl_info->gl_ops.gl.p_glReadBuffer(wined3d_texture_get_gl_buffer(&texture_gl->t));
|
2010-06-22 12:49:07 +02:00
|
|
|
checkGLcall("glReadBuffer");
|
2008-02-10 22:20:15 +01:00
|
|
|
|
2018-10-30 10:48:44 +01:00
|
|
|
level = sub_resource_idx % texture_gl->t.level_count;
|
|
|
|
target = wined3d_texture_gl_get_sub_resource_target(texture_gl, sub_resource_idx);
|
2018-02-28 07:26:57 +01:00
|
|
|
gl_info->gl_ops.gl.p_glCopyTexSubImage2D(target, level, 0, 0, 0, 0,
|
2018-10-30 10:48:44 +01:00
|
|
|
wined3d_texture_get_level_width(&texture_gl->t, level),
|
|
|
|
wined3d_texture_get_level_height(&texture_gl->t, level));
|
2008-02-10 22:20:15 +01:00
|
|
|
checkGLcall("glCopyTexSubImage2D");
|
|
|
|
|
2018-03-09 07:31:51 +01:00
|
|
|
if (restore_texture)
|
2018-03-12 10:06:47 +01:00
|
|
|
context_restore(context, restore_texture, restore_idx);
|
2008-02-10 22:20:15 +01:00
|
|
|
}
|
|
|
|
|
2017-04-04 09:07:43 +02:00
|
|
|
/* Context activation is done by the caller. */
|
|
|
|
static void cpu_blitter_destroy(struct wined3d_blitter *blitter, struct wined3d_context *context)
|
2011-04-29 13:03:40 +02:00
|
|
|
{
|
2017-04-04 09:07:43 +02:00
|
|
|
struct wined3d_blitter *next;
|
2009-10-28 11:00:11 +01:00
|
|
|
|
2017-04-04 09:07:43 +02:00
|
|
|
if ((next = blitter->next))
|
|
|
|
next->ops->blitter_destroy(next, context);
|
2017-06-16 16:01:58 +02:00
|
|
|
|
2018-02-14 07:39:59 +01:00
|
|
|
heap_free(blitter);
|
2011-04-29 13:03:40 +02:00
|
|
|
}
|
2008-04-06 01:54:26 +02:00
|
|
|
|
2011-09-08 23:50:37 +02:00
|
|
|
static HRESULT surface_cpu_blt_compressed(const BYTE *src_data, BYTE *dst_data,
|
|
|
|
UINT src_pitch, UINT dst_pitch, UINT update_w, UINT update_h,
|
2016-02-15 18:18:03 +01:00
|
|
|
const struct wined3d_format *format, DWORD flags, const struct wined3d_blt_fx *fx)
|
2011-09-08 23:50:37 +02:00
|
|
|
{
|
|
|
|
UINT row_block_count;
|
|
|
|
const BYTE *src_row;
|
|
|
|
BYTE *dst_row;
|
|
|
|
UINT x, y;
|
|
|
|
|
|
|
|
src_row = src_data;
|
|
|
|
dst_row = dst_data;
|
|
|
|
|
|
|
|
row_block_count = (update_w + format->block_width - 1) / format->block_width;
|
|
|
|
|
|
|
|
if (!flags)
|
|
|
|
{
|
|
|
|
for (y = 0; y < update_h; y += format->block_height)
|
|
|
|
{
|
|
|
|
memcpy(dst_row, src_row, row_block_count * format->block_byte_count);
|
|
|
|
src_row += src_pitch;
|
|
|
|
dst_row += dst_pitch;
|
|
|
|
}
|
|
|
|
|
|
|
|
return WINED3D_OK;
|
|
|
|
}
|
|
|
|
|
2016-02-15 18:18:03 +01:00
|
|
|
if (flags == WINED3D_BLT_FX && fx->fx == WINEDDBLTFX_MIRRORUPDOWN)
|
2011-09-08 23:50:37 +02:00
|
|
|
{
|
|
|
|
src_row += (((update_h / format->block_height) - 1) * src_pitch);
|
|
|
|
|
|
|
|
switch (format->id)
|
|
|
|
{
|
|
|
|
case WINED3DFMT_DXT1:
|
|
|
|
for (y = 0; y < update_h; y += format->block_height)
|
|
|
|
{
|
|
|
|
struct block
|
|
|
|
{
|
|
|
|
WORD color[2];
|
|
|
|
BYTE control_row[4];
|
|
|
|
};
|
|
|
|
|
|
|
|
const struct block *s = (const struct block *)src_row;
|
|
|
|
struct block *d = (struct block *)dst_row;
|
|
|
|
|
|
|
|
for (x = 0; x < row_block_count; ++x)
|
|
|
|
{
|
|
|
|
d[x].color[0] = s[x].color[0];
|
|
|
|
d[x].color[1] = s[x].color[1];
|
|
|
|
d[x].control_row[0] = s[x].control_row[3];
|
|
|
|
d[x].control_row[1] = s[x].control_row[2];
|
|
|
|
d[x].control_row[2] = s[x].control_row[1];
|
|
|
|
d[x].control_row[3] = s[x].control_row[0];
|
|
|
|
}
|
|
|
|
src_row -= src_pitch;
|
|
|
|
dst_row += dst_pitch;
|
|
|
|
}
|
|
|
|
return WINED3D_OK;
|
|
|
|
|
2014-05-12 15:12:41 +02:00
|
|
|
case WINED3DFMT_DXT2:
|
2011-09-08 23:50:37 +02:00
|
|
|
case WINED3DFMT_DXT3:
|
|
|
|
for (y = 0; y < update_h; y += format->block_height)
|
|
|
|
{
|
|
|
|
struct block
|
|
|
|
{
|
|
|
|
WORD alpha_row[4];
|
|
|
|
WORD color[2];
|
|
|
|
BYTE control_row[4];
|
|
|
|
};
|
|
|
|
|
|
|
|
const struct block *s = (const struct block *)src_row;
|
|
|
|
struct block *d = (struct block *)dst_row;
|
|
|
|
|
|
|
|
for (x = 0; x < row_block_count; ++x)
|
|
|
|
{
|
|
|
|
d[x].alpha_row[0] = s[x].alpha_row[3];
|
|
|
|
d[x].alpha_row[1] = s[x].alpha_row[2];
|
|
|
|
d[x].alpha_row[2] = s[x].alpha_row[1];
|
|
|
|
d[x].alpha_row[3] = s[x].alpha_row[0];
|
|
|
|
d[x].color[0] = s[x].color[0];
|
|
|
|
d[x].color[1] = s[x].color[1];
|
|
|
|
d[x].control_row[0] = s[x].control_row[3];
|
|
|
|
d[x].control_row[1] = s[x].control_row[2];
|
|
|
|
d[x].control_row[2] = s[x].control_row[1];
|
|
|
|
d[x].control_row[3] = s[x].control_row[0];
|
|
|
|
}
|
|
|
|
src_row -= src_pitch;
|
|
|
|
dst_row += dst_pitch;
|
|
|
|
}
|
|
|
|
return WINED3D_OK;
|
|
|
|
|
|
|
|
default:
|
|
|
|
FIXME("Compressed flip not implemented for format %s.\n",
|
|
|
|
debug_d3dformat(format->id));
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
FIXME("Unsupported blit on compressed surface (format %s, flags %#x, DDFX %#x).\n",
|
2016-02-15 18:18:03 +01:00
|
|
|
debug_d3dformat(format->id), flags, flags & WINED3D_BLT_FX ? fx->fx : 0);
|
2011-09-08 23:50:37 +02:00
|
|
|
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
2016-03-07 17:05:54 +01:00
|
|
|
static HRESULT surface_cpu_blt(struct wined3d_texture *dst_texture, unsigned int dst_sub_resource_idx,
|
|
|
|
const struct wined3d_box *dst_box, struct wined3d_texture *src_texture, unsigned int src_sub_resource_idx,
|
|
|
|
const struct wined3d_box *src_box, DWORD flags, const struct wined3d_blt_fx *fx,
|
|
|
|
enum wined3d_texture_filter_type filter)
|
2011-04-29 13:03:40 +02:00
|
|
|
{
|
2016-03-07 17:05:54 +01:00
|
|
|
unsigned int bpp, src_height, src_width, dst_height, dst_width, row_byte_count;
|
2017-04-19 23:40:51 +02:00
|
|
|
struct wined3d_device *device = dst_texture->resource.device;
|
2011-04-29 13:03:40 +02:00
|
|
|
const struct wined3d_format *src_format, *dst_format;
|
2016-03-07 17:05:54 +01:00
|
|
|
struct wined3d_texture *converted_texture = NULL;
|
2017-04-19 23:40:51 +02:00
|
|
|
struct wined3d_bo_address src_data, dst_data;
|
2015-04-22 11:30:15 +02:00
|
|
|
unsigned int src_fmt_flags, dst_fmt_flags;
|
2012-04-12 22:49:04 +02:00
|
|
|
struct wined3d_map_desc dst_map, src_map;
|
2017-04-11 23:24:22 +02:00
|
|
|
unsigned int x, sx, xinc, y, sy, yinc;
|
2019-08-15 23:01:38 +02:00
|
|
|
struct wined3d_context *context;
|
2020-02-27 13:31:10 +01:00
|
|
|
struct wined3d_range dst_range;
|
2017-04-19 23:40:51 +02:00
|
|
|
unsigned int texture_level;
|
2011-04-29 13:03:40 +02:00
|
|
|
HRESULT hr = WINED3D_OK;
|
2016-03-07 17:05:54 +01:00
|
|
|
BOOL same_sub_resource;
|
2019-12-02 14:27:10 +01:00
|
|
|
BOOL upload = FALSE;
|
2017-04-19 23:40:51 +02:00
|
|
|
DWORD map_binding;
|
2017-04-11 23:24:22 +02:00
|
|
|
const BYTE *sbase;
|
2011-04-29 13:03:40 +02:00
|
|
|
const BYTE *sbuf;
|
|
|
|
BYTE *dbuf;
|
2008-01-07 21:18:34 +01:00
|
|
|
|
2016-03-07 17:05:54 +01:00
|
|
|
TRACE("dst_texture %p, dst_sub_resource_idx %u, dst_box %s, src_texture %p, "
|
|
|
|
"src_sub_resource_idx %u, src_box %s, flags %#x, fx %p, filter %s.\n",
|
|
|
|
dst_texture, dst_sub_resource_idx, debug_box(dst_box), src_texture,
|
|
|
|
src_sub_resource_idx, debug_box(src_box), flags, fx, debug_d3dtexturefiltertype(filter));
|
2008-01-07 21:18:34 +01:00
|
|
|
|
2019-08-15 23:01:38 +02:00
|
|
|
context = context_acquire(device, NULL, 0);
|
2017-04-19 23:40:51 +02:00
|
|
|
|
2019-09-24 16:20:44 +02:00
|
|
|
src_format = src_texture->resource.format;
|
|
|
|
dst_format = dst_texture->resource.format;
|
|
|
|
|
|
|
|
if (wined3d_format_is_typeless(src_format) && src_format->id == dst_format->typeless_id)
|
|
|
|
src_format = dst_format;
|
|
|
|
if (wined3d_format_is_typeless(dst_format) && dst_format->id == src_format->typeless_id)
|
|
|
|
dst_format = src_format;
|
|
|
|
|
2019-12-02 14:27:10 +01:00
|
|
|
src_height = src_box->bottom - src_box->top;
|
|
|
|
src_width = src_box->right - src_box->left;
|
|
|
|
dst_height = dst_box->bottom - dst_box->top;
|
|
|
|
dst_width = dst_box->right - dst_box->left;
|
|
|
|
|
2019-09-23 13:24:16 +02:00
|
|
|
dst_range.offset = 0;
|
|
|
|
dst_range.size = dst_texture->sub_resources[dst_sub_resource_idx].size;
|
2016-03-07 17:05:54 +01:00
|
|
|
if (src_texture == dst_texture && src_sub_resource_idx == dst_sub_resource_idx)
|
2010-07-21 18:48:22 +02:00
|
|
|
{
|
2016-03-07 17:05:54 +01:00
|
|
|
same_sub_resource = TRUE;
|
2017-04-19 23:40:51 +02:00
|
|
|
|
|
|
|
map_binding = dst_texture->resource.map_binding;
|
|
|
|
texture_level = dst_sub_resource_idx % dst_texture->level_count;
|
|
|
|
if (!wined3d_texture_load_location(dst_texture, dst_sub_resource_idx, context, map_binding))
|
|
|
|
ERR("Failed to load the destination sub-resource into %s.\n", wined3d_debug_location(map_binding));
|
|
|
|
wined3d_texture_invalidate_location(dst_texture, dst_sub_resource_idx, ~map_binding);
|
|
|
|
wined3d_texture_get_pitch(dst_texture, texture_level, &dst_map.row_pitch, &dst_map.slice_pitch);
|
|
|
|
wined3d_texture_get_memory(dst_texture, dst_sub_resource_idx, &dst_data, map_binding);
|
2019-08-15 23:01:38 +02:00
|
|
|
dst_map.data = wined3d_context_map_bo_address(context, &dst_data,
|
2020-04-22 15:12:46 +02:00
|
|
|
dst_texture->sub_resources[dst_sub_resource_idx].size, WINED3D_MAP_READ | WINED3D_MAP_WRITE);
|
2017-04-19 23:40:51 +02:00
|
|
|
|
2011-12-05 22:06:56 +01:00
|
|
|
src_map = dst_map;
|
2007-09-25 00:21:34 +02:00
|
|
|
}
|
2011-04-29 13:03:40 +02:00
|
|
|
else
|
2011-03-03 09:24:10 +01:00
|
|
|
{
|
2016-03-07 17:05:54 +01:00
|
|
|
same_sub_resource = FALSE;
|
2019-12-02 14:27:10 +01:00
|
|
|
upload = dst_format->flags[dst_texture->resource.gl_type] & WINED3DFMT_FLAG_BLOCKS
|
|
|
|
&& (dst_width != src_width || dst_height != src_height);
|
|
|
|
|
|
|
|
if (upload)
|
|
|
|
{
|
|
|
|
dst_format = src_format->flags[dst_texture->resource.gl_type] & WINED3DFMT_FLAG_BLOCKS
|
|
|
|
? wined3d_get_format(device->adapter, WINED3DFMT_B8G8R8A8_UNORM, 0) : src_format;
|
|
|
|
}
|
|
|
|
|
2019-09-24 16:20:44 +02:00
|
|
|
if (!(flags & WINED3D_BLT_RAW) && dst_format->id != src_format->id)
|
2011-04-29 13:03:40 +02:00
|
|
|
{
|
2017-04-11 23:24:22 +02:00
|
|
|
if (!(converted_texture = surface_convert_format(src_texture, src_sub_resource_idx, dst_format)))
|
2011-04-29 13:03:40 +02:00
|
|
|
{
|
2019-09-24 16:20:44 +02:00
|
|
|
FIXME("Cannot convert %s to %s.\n", debug_d3dformat(src_format->id),
|
|
|
|
debug_d3dformat(dst_format->id));
|
2019-08-15 23:01:38 +02:00
|
|
|
context_release(context);
|
2017-04-11 23:24:22 +02:00
|
|
|
return WINED3DERR_NOTAVAILABLE;
|
2011-04-29 13:03:40 +02:00
|
|
|
}
|
2017-04-11 23:24:22 +02:00
|
|
|
src_texture = converted_texture;
|
|
|
|
src_sub_resource_idx = 0;
|
2019-09-24 16:20:44 +02:00
|
|
|
src_format = src_texture->resource.format;
|
2011-04-29 13:03:40 +02:00
|
|
|
}
|
2012-03-11 22:03:09 +01:00
|
|
|
|
2017-04-19 23:40:51 +02:00
|
|
|
map_binding = src_texture->resource.map_binding;
|
|
|
|
texture_level = src_sub_resource_idx % src_texture->level_count;
|
|
|
|
if (!wined3d_texture_load_location(src_texture, src_sub_resource_idx, context, map_binding))
|
|
|
|
ERR("Failed to load the source sub-resource into %s.\n", wined3d_debug_location(map_binding));
|
|
|
|
wined3d_texture_get_pitch(src_texture, texture_level, &src_map.row_pitch, &src_map.slice_pitch);
|
|
|
|
wined3d_texture_get_memory(src_texture, src_sub_resource_idx, &src_data, map_binding);
|
2019-08-15 23:01:38 +02:00
|
|
|
src_map.data = wined3d_context_map_bo_address(context, &src_data,
|
2020-04-22 15:12:46 +02:00
|
|
|
src_texture->sub_resources[src_sub_resource_idx].size, WINED3D_MAP_READ);
|
2017-04-19 23:40:51 +02:00
|
|
|
|
2019-12-02 14:27:10 +01:00
|
|
|
if (upload)
|
|
|
|
{
|
|
|
|
wined3d_format_calculate_pitch(dst_format, 1, dst_box->right, dst_box->bottom,
|
|
|
|
&dst_map.row_pitch, &dst_map.slice_pitch);
|
|
|
|
dst_map.data = heap_alloc(dst_map.slice_pitch);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
map_binding = dst_texture->resource.map_binding;
|
|
|
|
texture_level = dst_sub_resource_idx % dst_texture->level_count;
|
|
|
|
if (!wined3d_texture_load_location(dst_texture, dst_sub_resource_idx, context, map_binding))
|
|
|
|
ERR("Failed to load the destination sub-resource into %s.\n", wined3d_debug_location(map_binding));
|
|
|
|
|
|
|
|
wined3d_texture_invalidate_location(dst_texture, dst_sub_resource_idx, ~map_binding);
|
|
|
|
wined3d_texture_get_pitch(dst_texture, texture_level, &dst_map.row_pitch, &dst_map.slice_pitch);
|
|
|
|
wined3d_texture_get_memory(dst_texture, dst_sub_resource_idx, &dst_data, map_binding);
|
|
|
|
dst_map.data = wined3d_context_map_bo_address(context, &dst_data,
|
2020-04-22 15:12:46 +02:00
|
|
|
dst_texture->sub_resources[dst_sub_resource_idx].size, WINED3D_MAP_WRITE);
|
2019-12-02 14:27:10 +01:00
|
|
|
}
|
2011-03-03 09:24:10 +01:00
|
|
|
}
|
2019-09-24 16:20:44 +02:00
|
|
|
src_fmt_flags = src_format->flags[src_texture->resource.gl_type];
|
|
|
|
dst_fmt_flags = dst_format->flags[dst_texture->resource.gl_type];
|
2017-11-15 22:13:01 +01:00
|
|
|
flags &= ~WINED3D_BLT_RAW;
|
2011-03-03 09:24:10 +01:00
|
|
|
|
2016-03-07 17:05:54 +01:00
|
|
|
bpp = dst_format->byte_count;
|
|
|
|
row_byte_count = dst_width * bpp;
|
2010-04-05 20:05:14 +02:00
|
|
|
|
2017-04-11 23:24:22 +02:00
|
|
|
sbase = (BYTE *)src_map.data
|
|
|
|
+ ((src_box->top / src_format->block_height) * src_map.row_pitch)
|
|
|
|
+ ((src_box->left / src_format->block_width) * src_format->block_byte_count);
|
2017-04-19 23:40:51 +02:00
|
|
|
dbuf = (BYTE *)dst_map.data
|
|
|
|
+ ((dst_box->top / dst_format->block_height) * dst_map.row_pitch)
|
|
|
|
+ ((dst_box->left / dst_format->block_width) * dst_format->block_byte_count);
|
2012-03-11 22:03:08 +01:00
|
|
|
|
2015-04-22 11:30:15 +02:00
|
|
|
if (src_fmt_flags & dst_fmt_flags & WINED3DFMT_FLAG_BLOCKS)
|
2011-08-21 21:34:51 +02:00
|
|
|
{
|
2011-09-08 23:50:37 +02:00
|
|
|
TRACE("%s -> %s copy.\n", debug_d3dformat(src_format->id), debug_d3dformat(dst_format->id));
|
2011-08-21 21:34:51 +02:00
|
|
|
|
2016-03-07 17:05:54 +01:00
|
|
|
if (same_sub_resource)
|
2011-08-21 21:34:51 +02:00
|
|
|
{
|
|
|
|
FIXME("Only plain blits supported on compressed surfaces.\n");
|
|
|
|
hr = E_NOTIMPL;
|
|
|
|
goto release;
|
|
|
|
}
|
|
|
|
|
2012-03-11 22:03:08 +01:00
|
|
|
hr = surface_cpu_blt_compressed(sbase, dbuf,
|
2016-03-07 17:05:54 +01:00
|
|
|
src_map.row_pitch, dst_map.row_pitch, dst_width, dst_height,
|
2011-09-08 23:50:37 +02:00
|
|
|
src_format, flags, fx);
|
2011-08-21 21:34:51 +02:00
|
|
|
goto release;
|
|
|
|
}
|
|
|
|
|
2017-04-11 23:24:22 +02:00
|
|
|
if (filter != WINED3D_TEXF_NONE && filter != WINED3D_TEXF_POINT
|
|
|
|
&& (src_width != dst_width || src_height != dst_height))
|
2011-04-29 13:03:40 +02:00
|
|
|
{
|
2017-04-11 23:24:22 +02:00
|
|
|
/* Can happen when d3d9 apps do a StretchRect() call which isn't handled in GL. */
|
|
|
|
FIXME("Filter %s not supported in software blit.\n", debug_d3dtexturefiltertype(filter));
|
|
|
|
}
|
2010-04-12 12:17:09 +02:00
|
|
|
|
2017-04-11 23:24:22 +02:00
|
|
|
xinc = (src_width << 16) / dst_width;
|
|
|
|
yinc = (src_height << 16) / dst_height;
|
2011-04-29 13:03:40 +02:00
|
|
|
|
2017-04-11 23:24:22 +02:00
|
|
|
if (!flags)
|
|
|
|
{
|
|
|
|
/* No effects, we can cheat here. */
|
|
|
|
if (dst_width == src_width)
|
2011-04-29 13:03:40 +02:00
|
|
|
{
|
2017-04-11 23:24:22 +02:00
|
|
|
if (dst_height == src_height)
|
2011-04-05 19:01:31 +02:00
|
|
|
{
|
2017-04-11 23:24:22 +02:00
|
|
|
/* No stretching in either direction. This needs to be as fast
|
|
|
|
* as possible. */
|
|
|
|
sbuf = sbase;
|
2011-04-29 13:03:40 +02:00
|
|
|
|
2017-04-11 23:24:22 +02:00
|
|
|
/* Check for overlapping surfaces. */
|
|
|
|
if (!same_sub_resource || dst_box->top < src_box->top
|
|
|
|
|| dst_box->right <= src_box->left || src_box->right <= dst_box->left)
|
|
|
|
{
|
|
|
|
/* No overlap, or dst above src, so copy from top downwards. */
|
|
|
|
for (y = 0; y < dst_height; ++y)
|
2011-04-29 13:03:40 +02:00
|
|
|
{
|
2017-04-11 23:24:22 +02:00
|
|
|
memcpy(dbuf, sbuf, row_byte_count);
|
|
|
|
sbuf += src_map.row_pitch;
|
|
|
|
dbuf += dst_map.row_pitch;
|
2011-04-29 13:03:40 +02:00
|
|
|
}
|
2017-04-11 23:24:22 +02:00
|
|
|
}
|
|
|
|
else if (dst_box->top > src_box->top)
|
|
|
|
{
|
|
|
|
/* Copy from bottom upwards. */
|
|
|
|
sbuf += src_map.row_pitch * dst_height;
|
|
|
|
dbuf += dst_map.row_pitch * dst_height;
|
|
|
|
for (y = 0; y < dst_height; ++y)
|
2011-04-29 13:03:40 +02:00
|
|
|
{
|
2017-04-11 23:24:22 +02:00
|
|
|
sbuf -= src_map.row_pitch;
|
|
|
|
dbuf -= dst_map.row_pitch;
|
|
|
|
memcpy(dbuf, sbuf, row_byte_count);
|
2011-04-29 13:03:40 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-04-11 23:24:22 +02:00
|
|
|
/* Src and dst overlapping on the same line, use memmove. */
|
|
|
|
for (y = 0; y < dst_height; ++y)
|
2011-04-29 13:03:40 +02:00
|
|
|
{
|
2017-04-11 23:24:22 +02:00
|
|
|
memmove(dbuf, sbuf, row_byte_count);
|
|
|
|
sbuf += src_map.row_pitch;
|
2011-12-05 22:06:56 +01:00
|
|
|
dbuf += dst_map.row_pitch;
|
2011-04-29 13:03:40 +02:00
|
|
|
}
|
|
|
|
}
|
2011-04-05 19:01:31 +02:00
|
|
|
}
|
2011-04-29 13:03:40 +02:00
|
|
|
else
|
|
|
|
{
|
2017-04-11 23:24:22 +02:00
|
|
|
/* Stretching in y direction only. */
|
2016-03-07 17:05:54 +01:00
|
|
|
for (y = sy = 0; y < dst_height; ++y, sy += yinc)
|
2011-04-29 13:03:40 +02:00
|
|
|
{
|
2011-12-05 22:06:56 +01:00
|
|
|
sbuf = sbase + (sy >> 16) * src_map.row_pitch;
|
2017-04-11 23:24:22 +02:00
|
|
|
memcpy(dbuf, sbuf, row_byte_count);
|
|
|
|
dbuf += dst_map.row_pitch;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Stretching in X direction. */
|
|
|
|
unsigned int last_sy = ~0u;
|
|
|
|
for (y = sy = 0; y < dst_height; ++y, sy += yinc)
|
|
|
|
{
|
|
|
|
sbuf = sbase + (sy >> 16) * src_map.row_pitch;
|
2010-04-12 12:17:09 +02:00
|
|
|
|
2017-04-11 23:24:22 +02:00
|
|
|
if ((sy >> 16) == (last_sy >> 16))
|
|
|
|
{
|
|
|
|
/* This source row is the same as last source row -
|
|
|
|
* Copy the already stretched row. */
|
|
|
|
memcpy(dbuf, dbuf - dst_map.row_pitch, row_byte_count);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-04-29 13:03:40 +02:00
|
|
|
#define STRETCH_ROW(type) \
|
|
|
|
do { \
|
|
|
|
const type *s = (const type *)sbuf; \
|
|
|
|
type *d = (type *)dbuf; \
|
2016-03-07 17:05:54 +01:00
|
|
|
for (x = sx = 0; x < dst_width; ++x, sx += xinc) \
|
2011-04-29 13:03:40 +02:00
|
|
|
d[x] = s[sx >> 16]; \
|
|
|
|
} while(0)
|
|
|
|
|
2017-04-11 23:24:22 +02:00
|
|
|
switch(bpp)
|
|
|
|
{
|
|
|
|
case 1:
|
|
|
|
STRETCH_ROW(BYTE);
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
STRETCH_ROW(WORD);
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
STRETCH_ROW(DWORD);
|
|
|
|
break;
|
|
|
|
case 3:
|
2011-04-29 13:03:40 +02:00
|
|
|
{
|
2017-04-11 23:24:22 +02:00
|
|
|
const BYTE *s;
|
|
|
|
BYTE *d = dbuf;
|
|
|
|
for (x = sx = 0; x < dst_width; x++, sx+= xinc)
|
2011-04-29 13:03:40 +02:00
|
|
|
{
|
2017-04-11 23:24:22 +02:00
|
|
|
DWORD pixel;
|
|
|
|
|
|
|
|
s = sbuf + 3 * (sx >> 16);
|
|
|
|
pixel = s[0] | (s[1] << 8) | (s[2] << 16);
|
|
|
|
d[0] = (pixel ) & 0xff;
|
|
|
|
d[1] = (pixel >> 8) & 0xff;
|
|
|
|
d[2] = (pixel >> 16) & 0xff;
|
|
|
|
d += 3;
|
2011-04-29 13:03:40 +02:00
|
|
|
}
|
2017-04-11 23:24:22 +02:00
|
|
|
break;
|
2011-04-29 13:03:40 +02:00
|
|
|
}
|
2017-04-11 23:24:22 +02:00
|
|
|
default:
|
|
|
|
FIXME("Stretched blit not implemented for bpp %u.\n", bpp * 8);
|
|
|
|
hr = WINED3DERR_NOTAVAILABLE;
|
|
|
|
goto error;
|
2011-04-29 13:03:40 +02:00
|
|
|
}
|
2017-04-11 23:24:22 +02:00
|
|
|
#undef STRETCH_ROW
|
2011-04-29 13:03:40 +02:00
|
|
|
}
|
2017-04-11 23:24:22 +02:00
|
|
|
dbuf += dst_map.row_pitch;
|
|
|
|
last_sy = sy;
|
2011-04-29 13:03:40 +02:00
|
|
|
}
|
|
|
|
}
|
2017-04-11 23:24:22 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
LONG dstyinc = dst_map.row_pitch, dstxinc = bpp;
|
|
|
|
DWORD keylow = 0xffffffff, keyhigh = 0, keymask = 0xffffffff;
|
|
|
|
DWORD destkeylow = 0x0, destkeyhigh = 0xffffffff, destkeymask = 0xffffffff;
|
|
|
|
if (flags & (WINED3D_BLT_SRC_CKEY | WINED3D_BLT_DST_CKEY
|
|
|
|
| WINED3D_BLT_SRC_CKEY_OVERRIDE | WINED3D_BLT_DST_CKEY_OVERRIDE))
|
2011-04-29 13:03:40 +02:00
|
|
|
{
|
2017-04-11 23:24:22 +02:00
|
|
|
/* The color keying flags are checked for correctness in ddraw. */
|
|
|
|
if (flags & WINED3D_BLT_SRC_CKEY)
|
2011-04-05 19:01:31 +02:00
|
|
|
{
|
2017-04-11 23:24:22 +02:00
|
|
|
keylow = src_texture->async.src_blt_color_key.color_space_low_value;
|
|
|
|
keyhigh = src_texture->async.src_blt_color_key.color_space_high_value;
|
|
|
|
}
|
|
|
|
else if (flags & WINED3D_BLT_SRC_CKEY_OVERRIDE)
|
|
|
|
{
|
|
|
|
keylow = fx->src_color_key.color_space_low_value;
|
|
|
|
keyhigh = fx->src_color_key.color_space_high_value;
|
|
|
|
}
|
2011-04-29 13:03:40 +02:00
|
|
|
|
2017-04-11 23:24:22 +02:00
|
|
|
if (flags & WINED3D_BLT_DST_CKEY)
|
|
|
|
{
|
|
|
|
/* Destination color keys are taken from the source surface! */
|
|
|
|
destkeylow = src_texture->async.dst_blt_color_key.color_space_low_value;
|
|
|
|
destkeyhigh = src_texture->async.dst_blt_color_key.color_space_high_value;
|
|
|
|
}
|
|
|
|
else if (flags & WINED3D_BLT_DST_CKEY_OVERRIDE)
|
|
|
|
{
|
|
|
|
destkeylow = fx->dst_color_key.color_space_low_value;
|
|
|
|
destkeyhigh = fx->dst_color_key.color_space_high_value;
|
|
|
|
}
|
2011-04-29 13:03:40 +02:00
|
|
|
|
2017-04-11 23:24:22 +02:00
|
|
|
if (bpp == 1)
|
|
|
|
{
|
|
|
|
keymask = 0xff;
|
2011-04-05 19:01:31 +02:00
|
|
|
}
|
2017-04-11 23:24:22 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
DWORD masks[3];
|
|
|
|
get_color_masks(src_format, masks);
|
|
|
|
keymask = masks[0] | masks[1] | masks[2];
|
|
|
|
}
|
|
|
|
flags &= ~(WINED3D_BLT_SRC_CKEY | WINED3D_BLT_DST_CKEY
|
|
|
|
| WINED3D_BLT_SRC_CKEY_OVERRIDE | WINED3D_BLT_DST_CKEY_OVERRIDE);
|
|
|
|
}
|
2008-12-03 14:53:43 +01:00
|
|
|
|
2017-04-11 23:24:22 +02:00
|
|
|
if (flags & WINED3D_BLT_FX)
|
|
|
|
{
|
|
|
|
BYTE *dTopLeft, *dTopRight, *dBottomLeft, *dBottomRight, *tmp;
|
|
|
|
LONG tmpxy;
|
|
|
|
dTopLeft = dbuf;
|
|
|
|
dTopRight = dbuf + ((dst_width - 1) * bpp);
|
|
|
|
dBottomLeft = dTopLeft + ((dst_height - 1) * dst_map.row_pitch);
|
|
|
|
dBottomRight = dBottomLeft + ((dst_width - 1) * bpp);
|
|
|
|
|
|
|
|
if (fx->fx & WINEDDBLTFX_ARITHSTRETCHY)
|
2011-04-05 19:01:31 +02:00
|
|
|
{
|
2017-04-11 23:24:22 +02:00
|
|
|
/* I don't think we need to do anything about this flag. */
|
|
|
|
WARN("Nothing done for WINEDDBLTFX_ARITHSTRETCHY.\n");
|
|
|
|
}
|
|
|
|
if (fx->fx & WINEDDBLTFX_MIRRORLEFTRIGHT)
|
|
|
|
{
|
|
|
|
tmp = dTopRight;
|
|
|
|
dTopRight = dTopLeft;
|
|
|
|
dTopLeft = tmp;
|
|
|
|
tmp = dBottomRight;
|
|
|
|
dBottomRight = dBottomLeft;
|
|
|
|
dBottomLeft = tmp;
|
|
|
|
dstxinc = dstxinc * -1;
|
|
|
|
}
|
|
|
|
if (fx->fx & WINEDDBLTFX_MIRRORUPDOWN)
|
|
|
|
{
|
|
|
|
tmp = dTopLeft;
|
|
|
|
dTopLeft = dBottomLeft;
|
|
|
|
dBottomLeft = tmp;
|
|
|
|
tmp = dTopRight;
|
|
|
|
dTopRight = dBottomRight;
|
|
|
|
dBottomRight = tmp;
|
|
|
|
dstyinc = dstyinc * -1;
|
|
|
|
}
|
|
|
|
if (fx->fx & WINEDDBLTFX_NOTEARING)
|
|
|
|
{
|
|
|
|
/* I don't think we need to do anything about this flag. */
|
|
|
|
WARN("Nothing done for WINEDDBLTFX_NOTEARING.\n");
|
|
|
|
}
|
|
|
|
if (fx->fx & WINEDDBLTFX_ROTATE180)
|
|
|
|
{
|
|
|
|
tmp = dBottomRight;
|
|
|
|
dBottomRight = dTopLeft;
|
|
|
|
dTopLeft = tmp;
|
|
|
|
tmp = dBottomLeft;
|
|
|
|
dBottomLeft = dTopRight;
|
|
|
|
dTopRight = tmp;
|
|
|
|
dstxinc = dstxinc * -1;
|
|
|
|
dstyinc = dstyinc * -1;
|
|
|
|
}
|
|
|
|
if (fx->fx & WINEDDBLTFX_ROTATE270)
|
|
|
|
{
|
|
|
|
tmp = dTopLeft;
|
|
|
|
dTopLeft = dBottomLeft;
|
|
|
|
dBottomLeft = dBottomRight;
|
|
|
|
dBottomRight = dTopRight;
|
|
|
|
dTopRight = tmp;
|
|
|
|
tmpxy = dstxinc;
|
|
|
|
dstxinc = dstyinc;
|
|
|
|
dstyinc = tmpxy;
|
|
|
|
dstxinc = dstxinc * -1;
|
|
|
|
}
|
|
|
|
if (fx->fx & WINEDDBLTFX_ROTATE90)
|
|
|
|
{
|
|
|
|
tmp = dTopLeft;
|
|
|
|
dTopLeft = dTopRight;
|
|
|
|
dTopRight = dBottomRight;
|
|
|
|
dBottomRight = dBottomLeft;
|
|
|
|
dBottomLeft = tmp;
|
|
|
|
tmpxy = dstxinc;
|
|
|
|
dstxinc = dstyinc;
|
|
|
|
dstyinc = tmpxy;
|
|
|
|
dstyinc = dstyinc * -1;
|
2011-04-05 19:01:31 +02:00
|
|
|
}
|
2017-04-11 23:24:22 +02:00
|
|
|
if (fx->fx & WINEDDBLTFX_ZBUFFERBASEDEST)
|
|
|
|
{
|
|
|
|
/* I don't think we need to do anything about this flag. */
|
|
|
|
WARN("Nothing done for WINEDDBLTFX_ZBUFFERBASEDEST.\n");
|
|
|
|
}
|
|
|
|
dbuf = dTopLeft;
|
|
|
|
flags &= ~(WINED3D_BLT_FX);
|
|
|
|
}
|
2010-04-06 22:20:42 +02:00
|
|
|
|
2011-04-29 13:03:40 +02:00
|
|
|
#define COPY_COLORKEY_FX(type) \
|
|
|
|
do { \
|
|
|
|
const type *s; \
|
|
|
|
type *d = (type *)dbuf, *dx, tmp; \
|
2016-03-07 17:05:54 +01:00
|
|
|
for (y = sy = 0; y < dst_height; ++y, sy += yinc) \
|
2011-04-29 13:03:40 +02:00
|
|
|
{ \
|
2011-12-05 22:06:56 +01:00
|
|
|
s = (const type *)(sbase + (sy >> 16) * src_map.row_pitch); \
|
2011-04-29 13:03:40 +02:00
|
|
|
dx = d; \
|
2016-03-07 17:05:54 +01:00
|
|
|
for (x = sx = 0; x < dst_width; ++x, sx += xinc) \
|
2011-04-29 13:03:40 +02:00
|
|
|
{ \
|
|
|
|
tmp = s[sx >> 16]; \
|
|
|
|
if (((tmp & keymask) < keylow || (tmp & keymask) > keyhigh) \
|
|
|
|
&& ((dx[0] & destkeymask) >= destkeylow && (dx[0] & destkeymask) <= destkeyhigh)) \
|
|
|
|
{ \
|
|
|
|
dx[0] = tmp; \
|
|
|
|
} \
|
|
|
|
dx = (type *)(((BYTE *)dx) + dstxinc); \
|
|
|
|
} \
|
|
|
|
d = (type *)(((BYTE *)d) + dstyinc); \
|
|
|
|
} \
|
|
|
|
} while(0)
|
2008-12-03 14:53:43 +01:00
|
|
|
|
2017-04-11 23:24:22 +02:00
|
|
|
switch (bpp)
|
|
|
|
{
|
|
|
|
case 1:
|
|
|
|
COPY_COLORKEY_FX(BYTE);
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
COPY_COLORKEY_FX(WORD);
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
COPY_COLORKEY_FX(DWORD);
|
|
|
|
break;
|
|
|
|
case 3:
|
2011-04-05 19:01:31 +02:00
|
|
|
{
|
2017-04-11 23:24:22 +02:00
|
|
|
const BYTE *s;
|
|
|
|
BYTE *d = dbuf, *dx;
|
|
|
|
for (y = sy = 0; y < dst_height; ++y, sy += yinc)
|
2011-04-29 13:03:40 +02:00
|
|
|
{
|
2017-04-11 23:24:22 +02:00
|
|
|
sbuf = sbase + (sy >> 16) * src_map.row_pitch;
|
|
|
|
dx = d;
|
|
|
|
for (x = sx = 0; x < dst_width; ++x, sx+= xinc)
|
2011-04-29 13:03:40 +02:00
|
|
|
{
|
2017-04-11 23:24:22 +02:00
|
|
|
DWORD pixel, dpixel = 0;
|
|
|
|
s = sbuf + 3 * (sx>>16);
|
|
|
|
pixel = s[0] | (s[1] << 8) | (s[2] << 16);
|
|
|
|
dpixel = dx[0] | (dx[1] << 8 ) | (dx[2] << 16);
|
|
|
|
if (((pixel & keymask) < keylow || (pixel & keymask) > keyhigh)
|
|
|
|
&& ((dpixel & keymask) >= destkeylow || (dpixel & keymask) <= keyhigh))
|
2011-04-29 13:03:40 +02:00
|
|
|
{
|
2017-04-11 23:24:22 +02:00
|
|
|
dx[0] = (pixel ) & 0xff;
|
|
|
|
dx[1] = (pixel >> 8) & 0xff;
|
|
|
|
dx[2] = (pixel >> 16) & 0xff;
|
2011-04-29 13:03:40 +02:00
|
|
|
}
|
2017-04-11 23:24:22 +02:00
|
|
|
dx += dstxinc;
|
2011-04-29 13:03:40 +02:00
|
|
|
}
|
2017-04-11 23:24:22 +02:00
|
|
|
d += dstyinc;
|
2011-04-29 13:03:40 +02:00
|
|
|
}
|
2017-04-11 23:24:22 +02:00
|
|
|
break;
|
2011-04-05 19:01:31 +02:00
|
|
|
}
|
2017-04-11 23:24:22 +02:00
|
|
|
default:
|
|
|
|
FIXME("%s color-keyed blit not implemented for bpp %u.\n",
|
|
|
|
(flags & WINED3D_BLT_SRC_CKEY) ? "Source" : "Destination", bpp * 8);
|
|
|
|
hr = WINED3DERR_NOTAVAILABLE;
|
|
|
|
goto error;
|
|
|
|
#undef COPY_COLORKEY_FX
|
2011-04-29 13:03:40 +02:00
|
|
|
}
|
2011-04-05 19:01:31 +02:00
|
|
|
}
|
2010-03-25 17:01:33 +01:00
|
|
|
|
2011-04-29 13:03:40 +02:00
|
|
|
error:
|
2016-03-29 16:45:35 +02:00
|
|
|
if (flags)
|
|
|
|
FIXME(" Unsupported flags %#x.\n", flags);
|
2010-04-12 12:17:09 +02:00
|
|
|
|
2011-04-29 13:03:40 +02:00
|
|
|
release:
|
2019-12-02 14:27:10 +01:00
|
|
|
if (upload && hr == WINED3D_OK)
|
|
|
|
{
|
|
|
|
struct wined3d_bo_address data;
|
|
|
|
|
|
|
|
data.buffer_object = 0;
|
|
|
|
data.addr = dst_map.data;
|
|
|
|
|
|
|
|
texture_level = dst_sub_resource_idx % dst_texture->level_count;
|
|
|
|
|
|
|
|
wined3d_texture_prepare_location(dst_texture, texture_level, context, WINED3D_LOCATION_TEXTURE_RGB);
|
|
|
|
dst_texture->texture_ops->texture_upload_data(context, wined3d_const_bo_address(&data), dst_format,
|
|
|
|
dst_box, dst_map.row_pitch, dst_map.slice_pitch, dst_texture, texture_level,
|
|
|
|
WINED3D_LOCATION_TEXTURE_RGB, dst_box->left, dst_box->top, 0);
|
|
|
|
|
|
|
|
wined3d_texture_validate_location(dst_texture, texture_level, WINED3D_LOCATION_TEXTURE_RGB);
|
|
|
|
wined3d_texture_invalidate_location(dst_texture, texture_level, ~WINED3D_LOCATION_TEXTURE_RGB);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (upload)
|
|
|
|
{
|
|
|
|
heap_free(dst_map.data);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-04-22 15:12:45 +02:00
|
|
|
wined3d_context_unmap_bo_address(context, &dst_data, 1, &dst_range);
|
2019-12-02 14:27:10 +01:00
|
|
|
}
|
|
|
|
|
2017-04-11 23:24:22 +02:00
|
|
|
if (!same_sub_resource)
|
2020-04-22 15:12:45 +02:00
|
|
|
wined3d_context_unmap_bo_address(context, &src_data, 0, NULL);
|
2017-06-19 17:54:36 +02:00
|
|
|
if (SUCCEEDED(hr) && dst_texture->swapchain && dst_texture->swapchain->front_buffer == dst_texture)
|
|
|
|
{
|
|
|
|
SetRect(&dst_texture->swapchain->front_buffer_update,
|
|
|
|
dst_box->left, dst_box->top, dst_box->right, dst_box->bottom);
|
|
|
|
dst_texture->swapchain->swapchain_ops->swapchain_frontbuffer_updated(dst_texture->swapchain);
|
|
|
|
}
|
2016-03-07 17:05:54 +01:00
|
|
|
if (converted_texture)
|
|
|
|
wined3d_texture_decref(converted_texture);
|
2019-08-15 23:01:38 +02:00
|
|
|
context_release(context);
|
2011-04-29 13:03:40 +02:00
|
|
|
|
|
|
|
return hr;
|
2010-03-25 17:01:33 +01:00
|
|
|
}
|
|
|
|
|
2017-04-03 07:39:45 +02:00
|
|
|
static void surface_cpu_blt_colour_fill(struct wined3d_rendertarget_view *view,
|
2017-03-29 23:17:31 +02:00
|
|
|
const struct wined3d_box *box, const struct wined3d_color *colour)
|
2017-03-28 23:37:38 +02:00
|
|
|
{
|
2017-04-19 23:40:52 +02:00
|
|
|
struct wined3d_device *device = view->resource->device;
|
2019-08-15 11:50:03 +02:00
|
|
|
unsigned int x, y, z, w, h, d, bpp, level;
|
2019-08-15 23:01:38 +02:00
|
|
|
struct wined3d_context *context;
|
2017-04-19 23:40:52 +02:00
|
|
|
struct wined3d_texture *texture;
|
|
|
|
struct wined3d_bo_address data;
|
2017-03-28 23:37:38 +02:00
|
|
|
struct wined3d_map_desc map;
|
2020-02-27 13:31:10 +01:00
|
|
|
struct wined3d_range range;
|
2017-04-19 23:40:52 +02:00
|
|
|
DWORD map_binding;
|
2019-08-15 11:50:03 +02:00
|
|
|
uint8_t *dst;
|
2017-03-29 23:17:31 +02:00
|
|
|
DWORD c;
|
2017-03-28 23:37:38 +02:00
|
|
|
|
2017-03-29 23:17:31 +02:00
|
|
|
TRACE("view %p, box %s, colour %s.\n", view, debug_box(box), debug_color(colour));
|
2017-03-28 23:37:38 +02:00
|
|
|
|
2017-03-29 23:17:31 +02:00
|
|
|
if (view->format_flags & WINED3DFMT_FLAG_BLOCKS)
|
2017-03-28 23:37:38 +02:00
|
|
|
{
|
2017-03-29 23:17:31 +02:00
|
|
|
FIXME("Not implemented for format %s.\n", debug_d3dformat(view->format->id));
|
2017-04-03 07:39:45 +02:00
|
|
|
return;
|
2017-03-28 23:37:38 +02:00
|
|
|
}
|
|
|
|
|
2017-05-02 11:35:28 +02:00
|
|
|
if (view->format->id != view->resource->format->id)
|
|
|
|
FIXME("View format %s doesn't match resource format %s.\n",
|
|
|
|
debug_d3dformat(view->format->id), debug_d3dformat(view->resource->format->id));
|
|
|
|
|
2017-04-19 23:40:52 +02:00
|
|
|
if (view->resource->type == WINED3D_RTYPE_BUFFER)
|
|
|
|
{
|
|
|
|
FIXME("Not implemented for buffers.\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-08-15 23:01:38 +02:00
|
|
|
context = context_acquire(device, NULL, 0);
|
2017-04-19 23:40:52 +02:00
|
|
|
|
2019-08-15 11:50:03 +02:00
|
|
|
texture = texture_from_resource(view->resource);
|
|
|
|
level = view->sub_resource_idx % texture->level_count;
|
|
|
|
|
2017-03-29 23:17:31 +02:00
|
|
|
c = wined3d_format_convert_from_float(view->format, colour);
|
|
|
|
bpp = view->format->byte_count;
|
2019-01-16 15:29:34 +01:00
|
|
|
w = min(box->right, view->width) - min(box->left, view->width);
|
|
|
|
h = min(box->bottom, view->height) - min(box->top, view->height);
|
2019-08-15 11:50:03 +02:00
|
|
|
if (view->resource->type != WINED3D_RTYPE_TEXTURE_3D)
|
|
|
|
{
|
|
|
|
d = 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
d = wined3d_texture_get_level_depth(texture, level);
|
|
|
|
d = min(box->back, d) - min(box->front, d);
|
|
|
|
}
|
2017-03-28 23:37:38 +02:00
|
|
|
|
2017-04-19 23:40:52 +02:00
|
|
|
map_binding = texture->resource.map_binding;
|
|
|
|
if (!wined3d_texture_load_location(texture, view->sub_resource_idx, context, map_binding))
|
|
|
|
ERR("Failed to load the sub-resource into %s.\n", wined3d_debug_location(map_binding));
|
|
|
|
wined3d_texture_invalidate_location(texture, view->sub_resource_idx, ~map_binding);
|
2019-08-15 11:50:03 +02:00
|
|
|
wined3d_texture_get_pitch(texture, level, &map.row_pitch, &map.slice_pitch);
|
2017-04-19 23:40:52 +02:00
|
|
|
wined3d_texture_get_memory(texture, view->sub_resource_idx, &data, map_binding);
|
2019-08-15 23:01:38 +02:00
|
|
|
map.data = wined3d_context_map_bo_address(context, &data,
|
2020-04-22 15:12:46 +02:00
|
|
|
texture->sub_resources[view->sub_resource_idx].size, WINED3D_MAP_WRITE);
|
2017-04-19 23:40:52 +02:00
|
|
|
map.data = (BYTE *)map.data
|
|
|
|
+ (box->front * map.slice_pitch)
|
|
|
|
+ ((box->top / view->format->block_height) * map.row_pitch)
|
|
|
|
+ ((box->left / view->format->block_width) * view->format->block_byte_count);
|
2019-09-23 13:24:16 +02:00
|
|
|
range.offset = 0;
|
|
|
|
range.size = texture->sub_resources[view->sub_resource_idx].size;
|
2017-03-28 23:37:38 +02:00
|
|
|
|
|
|
|
switch (bpp)
|
|
|
|
{
|
|
|
|
case 1:
|
|
|
|
for (x = 0; x < w; ++x)
|
|
|
|
{
|
|
|
|
((BYTE *)map.data)[x] = c;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 2:
|
|
|
|
for (x = 0; x < w; ++x)
|
|
|
|
{
|
|
|
|
((WORD *)map.data)[x] = c;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 3:
|
|
|
|
{
|
2019-08-15 11:50:03 +02:00
|
|
|
dst = map.data;
|
|
|
|
for (x = 0; x < w; ++x, dst += 3)
|
2017-03-28 23:37:38 +02:00
|
|
|
{
|
2019-08-15 11:50:03 +02:00
|
|
|
dst[0] = (c ) & 0xff;
|
|
|
|
dst[1] = (c >> 8) & 0xff;
|
|
|
|
dst[2] = (c >> 16) & 0xff;
|
2017-03-28 23:37:38 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 4:
|
|
|
|
for (x = 0; x < w; ++x)
|
|
|
|
{
|
|
|
|
((DWORD *)map.data)[x] = c;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
FIXME("Not implemented for bpp %u.\n", bpp);
|
2017-03-29 23:17:31 +02:00
|
|
|
wined3d_resource_unmap(view->resource, view->sub_resource_idx);
|
2017-04-03 07:39:45 +02:00
|
|
|
return;
|
2017-03-28 23:37:38 +02:00
|
|
|
}
|
|
|
|
|
2019-08-15 11:50:03 +02:00
|
|
|
dst = map.data;
|
2017-03-28 23:37:38 +02:00
|
|
|
for (y = 1; y < h; ++y)
|
|
|
|
{
|
2019-08-15 11:50:03 +02:00
|
|
|
dst += map.row_pitch;
|
|
|
|
memcpy(dst, map.data, w * bpp);
|
|
|
|
}
|
|
|
|
|
|
|
|
dst = map.data;
|
|
|
|
for (z = 1; z < d; ++z)
|
|
|
|
{
|
|
|
|
dst += map.slice_pitch;
|
|
|
|
memcpy(dst, map.data, w * h * bpp);
|
2017-03-28 23:37:38 +02:00
|
|
|
}
|
2017-04-19 23:40:52 +02:00
|
|
|
|
2020-04-22 15:12:45 +02:00
|
|
|
wined3d_context_unmap_bo_address(context, &data, 1, &range);
|
2019-08-15 23:01:38 +02:00
|
|
|
context_release(context);
|
2017-03-28 23:37:38 +02:00
|
|
|
}
|
|
|
|
|
2017-04-04 09:07:43 +02:00
|
|
|
static void cpu_blitter_clear(struct wined3d_blitter *blitter, struct wined3d_device *device,
|
2017-04-04 09:07:47 +02:00
|
|
|
unsigned int rt_count, const struct wined3d_fb_state *fb, unsigned int rect_count, const RECT *clear_rects,
|
2017-04-04 09:07:46 +02:00
|
|
|
const RECT *draw_rect, DWORD flags, const struct wined3d_color *colour, float depth, DWORD stencil)
|
2010-03-25 17:01:33 +01:00
|
|
|
{
|
2017-04-03 07:39:45 +02:00
|
|
|
struct wined3d_color c = {depth, 0.0f, 0.0f, 0.0f};
|
2017-04-04 09:07:45 +02:00
|
|
|
struct wined3d_rendertarget_view *view;
|
2017-04-04 09:07:46 +02:00
|
|
|
struct wined3d_box box;
|
2017-04-04 09:07:47 +02:00
|
|
|
unsigned int i, j;
|
2017-04-04 09:07:46 +02:00
|
|
|
|
2017-04-04 09:07:47 +02:00
|
|
|
if (!rect_count)
|
|
|
|
{
|
|
|
|
rect_count = 1;
|
|
|
|
clear_rects = draw_rect;
|
|
|
|
}
|
2017-04-04 09:07:46 +02:00
|
|
|
|
2017-04-04 09:07:47 +02:00
|
|
|
for (i = 0; i < rect_count; ++i)
|
2017-04-03 07:39:45 +02:00
|
|
|
{
|
2017-04-04 09:07:47 +02:00
|
|
|
box.left = max(clear_rects[i].left, draw_rect->left);
|
|
|
|
box.top = max(clear_rects[i].top, draw_rect->top);
|
|
|
|
box.right = min(clear_rects[i].right, draw_rect->right);
|
|
|
|
box.bottom = min(clear_rects[i].bottom, draw_rect->bottom);
|
|
|
|
box.front = 0;
|
2019-08-15 11:50:03 +02:00
|
|
|
box.back = ~0u;
|
2017-04-04 09:07:47 +02:00
|
|
|
|
|
|
|
if (box.left >= box.right || box.top >= box.bottom)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (flags & WINED3DCLEAR_TARGET)
|
2017-04-04 09:07:45 +02:00
|
|
|
{
|
2017-04-04 09:07:47 +02:00
|
|
|
for (j = 0; j < rt_count; ++j)
|
|
|
|
{
|
|
|
|
if ((view = fb->render_targets[j]))
|
|
|
|
surface_cpu_blt_colour_fill(view, &box, colour);
|
|
|
|
}
|
2017-04-04 09:07:45 +02:00
|
|
|
}
|
2017-02-24 08:10:32 +01:00
|
|
|
|
2017-07-17 14:01:36 +02:00
|
|
|
if ((flags & (WINED3DCLEAR_ZBUFFER | WINED3DCLEAR_STENCIL)) && (view = fb->depth_stencil))
|
|
|
|
{
|
|
|
|
if ((view->format->depth_size && !(flags & WINED3DCLEAR_ZBUFFER))
|
|
|
|
|| (view->format->stencil_size && !(flags & WINED3DCLEAR_STENCIL)))
|
|
|
|
FIXME("Clearing %#x on %s.\n", flags, debug_d3dformat(view->format->id));
|
|
|
|
|
2017-04-04 09:07:47 +02:00
|
|
|
surface_cpu_blt_colour_fill(view, &box, &c);
|
2017-07-17 14:01:36 +02:00
|
|
|
}
|
2017-04-04 09:07:47 +02:00
|
|
|
}
|
2011-04-05 19:01:31 +02:00
|
|
|
}
|
|
|
|
|
2017-09-06 01:39:18 +02:00
|
|
|
static DWORD cpu_blitter_blit(struct wined3d_blitter *blitter, enum wined3d_blit_op op,
|
2018-03-13 11:23:01 +01:00
|
|
|
struct wined3d_context *context, struct wined3d_texture *src_texture, unsigned int src_sub_resource_idx,
|
|
|
|
DWORD src_location, const RECT *src_rect, struct wined3d_texture *dst_texture,
|
|
|
|
unsigned int dst_sub_resource_idx, DWORD dst_location, const RECT *dst_rect,
|
2021-03-31 12:27:37 +02:00
|
|
|
const struct wined3d_color_key *color_key, enum wined3d_texture_filter_type filter,
|
|
|
|
const struct wined3d_format *resolve_format)
|
2015-04-14 11:16:26 +02:00
|
|
|
{
|
2017-04-03 07:39:47 +02:00
|
|
|
struct wined3d_box dst_box = {dst_rect->left, dst_rect->top, dst_rect->right, dst_rect->bottom, 0, 1};
|
|
|
|
struct wined3d_box src_box = {src_rect->left, src_rect->top, src_rect->right, src_rect->bottom, 0, 1};
|
|
|
|
struct wined3d_blt_fx fx;
|
|
|
|
DWORD flags = 0;
|
|
|
|
|
|
|
|
memset(&fx, 0, sizeof(fx));
|
2017-04-04 09:07:43 +02:00
|
|
|
switch (op)
|
2017-04-03 07:39:47 +02:00
|
|
|
{
|
2017-04-04 09:07:43 +02:00
|
|
|
case WINED3D_BLIT_OP_COLOR_BLIT:
|
|
|
|
case WINED3D_BLIT_OP_DEPTH_BLIT:
|
2019-08-15 11:50:02 +02:00
|
|
|
break;
|
2017-11-15 22:13:00 +01:00
|
|
|
case WINED3D_BLIT_OP_RAW_BLIT:
|
2019-08-15 11:50:02 +02:00
|
|
|
flags |= WINED3D_BLT_RAW;
|
2017-04-04 09:07:43 +02:00
|
|
|
break;
|
|
|
|
case WINED3D_BLIT_OP_COLOR_BLIT_ALPHATEST:
|
|
|
|
flags |= WINED3D_BLT_ALPHA_TEST;
|
|
|
|
break;
|
|
|
|
case WINED3D_BLIT_OP_COLOR_BLIT_CKEY:
|
|
|
|
flags |= WINED3D_BLT_SRC_CKEY_OVERRIDE | WINED3D_BLT_FX;
|
|
|
|
fx.src_color_key = *color_key;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
FIXME("Unhandled op %#x.\n", op);
|
|
|
|
break;
|
2017-04-03 07:39:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (FAILED(surface_cpu_blt(dst_texture, dst_sub_resource_idx, &dst_box,
|
|
|
|
src_texture, src_sub_resource_idx, &src_box, flags, &fx, filter)))
|
|
|
|
ERR("Failed to blit.\n");
|
|
|
|
wined3d_texture_load_location(dst_texture, dst_sub_resource_idx, context, dst_location);
|
2017-09-06 01:39:18 +02:00
|
|
|
|
2017-09-15 15:12:22 +02:00
|
|
|
return dst_location | (dst_texture->sub_resources[dst_sub_resource_idx].locations
|
|
|
|
& dst_texture->resource.map_binding);
|
2015-04-14 11:16:26 +02:00
|
|
|
}
|
|
|
|
|
2017-04-04 09:07:43 +02:00
|
|
|
static const struct wined3d_blitter_ops cpu_blitter_ops =
|
2017-03-26 20:56:01 +02:00
|
|
|
{
|
2017-04-04 09:07:43 +02:00
|
|
|
cpu_blitter_destroy,
|
|
|
|
cpu_blitter_clear,
|
|
|
|
cpu_blitter_blit,
|
2008-08-01 20:21:10 +02:00
|
|
|
};
|
2010-03-31 13:54:57 +02:00
|
|
|
|
2017-04-04 09:07:43 +02:00
|
|
|
struct wined3d_blitter *wined3d_cpu_blitter_create(void)
|
|
|
|
{
|
|
|
|
struct wined3d_blitter *blitter;
|
|
|
|
|
2018-02-14 07:39:59 +01:00
|
|
|
if (!(blitter = heap_alloc(sizeof(*blitter))))
|
2017-04-04 09:07:43 +02:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
TRACE("Created blitter %p.\n", blitter);
|
|
|
|
|
|
|
|
blitter->ops = &cpu_blitter_ops;
|
|
|
|
blitter->next = NULL;
|
|
|
|
|
|
|
|
return blitter;
|
|
|
|
}
|
|
|
|
|
2020-05-28 20:02:17 +02:00
|
|
|
static bool wined3d_is_colour_blit(enum wined3d_blit_op blit_op)
|
|
|
|
{
|
|
|
|
switch (blit_op)
|
|
|
|
{
|
|
|
|
case WINED3D_BLIT_OP_COLOR_BLIT:
|
|
|
|
case WINED3D_BLIT_OP_COLOR_BLIT_ALPHATEST:
|
|
|
|
case WINED3D_BLIT_OP_COLOR_BLIT_CKEY:
|
|
|
|
return true;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-13 11:23:02 +01:00
|
|
|
HRESULT texture2d_blt(struct wined3d_texture *dst_texture, unsigned int dst_sub_resource_idx,
|
|
|
|
const struct wined3d_box *dst_box, struct wined3d_texture *src_texture, unsigned int src_sub_resource_idx,
|
|
|
|
const struct wined3d_box *src_box, DWORD flags, const struct wined3d_blt_fx *fx,
|
|
|
|
enum wined3d_texture_filter_type filter)
|
2013-09-02 09:45:42 +02:00
|
|
|
{
|
2017-04-04 09:07:44 +02:00
|
|
|
struct wined3d_texture_sub_resource *src_sub_resource, *dst_sub_resource;
|
2016-03-06 20:59:49 +01:00
|
|
|
struct wined3d_device *device = dst_texture->resource.device;
|
2013-09-02 09:45:42 +02:00
|
|
|
struct wined3d_swapchain *src_swapchain, *dst_swapchain;
|
2021-04-19 11:16:59 +02:00
|
|
|
BOOL scale, convert, resolve, resolve_typeless = FALSE;
|
2021-03-31 12:27:37 +02:00
|
|
|
const struct wined3d_format *resolve_format = NULL;
|
2017-04-04 09:07:44 +02:00
|
|
|
const struct wined3d_color_key *colour_key = NULL;
|
2020-03-12 10:49:48 +01:00
|
|
|
DWORD src_location, dst_location, valid_locations;
|
2017-04-04 09:07:43 +02:00
|
|
|
struct wined3d_context *context;
|
2017-04-04 09:07:44 +02:00
|
|
|
enum wined3d_blit_op blit_op;
|
2018-03-07 08:26:42 +01:00
|
|
|
RECT src_rect, dst_rect;
|
2020-06-03 13:10:11 +02:00
|
|
|
bool src_ds, dst_ds;
|
2013-09-02 09:45:42 +02:00
|
|
|
|
2017-04-24 23:31:31 +02:00
|
|
|
static const DWORD simple_blit = WINED3D_BLT_SRC_CKEY
|
2016-02-15 18:18:02 +01:00
|
|
|
| WINED3D_BLT_SRC_CKEY_OVERRIDE
|
2017-11-15 22:13:01 +01:00
|
|
|
| WINED3D_BLT_ALPHA_TEST
|
|
|
|
| WINED3D_BLT_RAW;
|
2013-09-02 09:45:42 +02:00
|
|
|
|
2018-03-13 11:23:02 +01:00
|
|
|
TRACE("dst_texture %p, dst_sub_resource_idx %u, dst_box %s, src_texture %p, "
|
|
|
|
"src_sub_resource_idx %u, src_box %s, flags %#x, fx %p, filter %s.\n",
|
|
|
|
dst_texture, dst_sub_resource_idx, debug_box(dst_box), src_texture, src_sub_resource_idx,
|
|
|
|
debug_box(src_box), flags, fx, debug_d3dtexturefiltertype(filter));
|
2016-03-06 20:59:49 +01:00
|
|
|
TRACE("Usage is %s.\n", debug_d3dusage(dst_texture->resource.usage));
|
2013-09-02 09:45:42 +02:00
|
|
|
|
|
|
|
if (fx)
|
|
|
|
{
|
2016-02-15 18:18:03 +01:00
|
|
|
TRACE("fx %#x.\n", fx->fx);
|
|
|
|
TRACE("dst_color_key {0x%08x, 0x%08x}.\n",
|
|
|
|
fx->dst_color_key.color_space_low_value,
|
|
|
|
fx->dst_color_key.color_space_high_value);
|
|
|
|
TRACE("src_color_key {0x%08x, 0x%08x}.\n",
|
|
|
|
fx->src_color_key.color_space_low_value,
|
|
|
|
fx->src_color_key.color_space_high_value);
|
2021-03-31 12:27:36 +02:00
|
|
|
TRACE("resolve_format_id %s.\n", debug_d3dformat(fx->resolve_format_id));
|
2021-03-31 12:27:37 +02:00
|
|
|
|
|
|
|
if (fx->resolve_format_id != WINED3DFMT_UNKNOWN)
|
|
|
|
resolve_format = wined3d_get_format(device->adapter, fx->resolve_format_id, 0);
|
2013-09-02 09:45:42 +02:00
|
|
|
}
|
|
|
|
|
2018-10-29 08:17:07 +01:00
|
|
|
dst_sub_resource = &dst_texture->sub_resources[dst_sub_resource_idx];
|
|
|
|
src_sub_resource = &src_texture->sub_resources[src_sub_resource_idx];
|
|
|
|
|
|
|
|
if (src_sub_resource->locations & WINED3D_LOCATION_DISCARDED)
|
|
|
|
{
|
|
|
|
WARN("Source sub-resource is discarded, nothing to do.\n");
|
|
|
|
return WINED3D_OK;
|
|
|
|
}
|
|
|
|
|
2018-03-07 08:26:42 +01:00
|
|
|
SetRect(&src_rect, src_box->left, src_box->top, src_box->right, src_box->bottom);
|
|
|
|
SetRect(&dst_rect, dst_box->left, dst_box->top, dst_box->right, dst_box->bottom);
|
|
|
|
|
2016-02-15 18:18:03 +01:00
|
|
|
if (!fx || !(fx->fx))
|
2016-02-15 18:18:02 +01:00
|
|
|
flags &= ~WINED3D_BLT_FX;
|
2013-09-02 09:45:42 +02:00
|
|
|
|
2016-02-15 18:18:02 +01:00
|
|
|
/* WINED3D_BLT_DO_NOT_WAIT appeared in DX7. */
|
|
|
|
if (flags & WINED3D_BLT_DO_NOT_WAIT)
|
2013-09-02 09:45:42 +02:00
|
|
|
{
|
|
|
|
static unsigned int once;
|
|
|
|
|
|
|
|
if (!once++)
|
2016-02-15 18:18:02 +01:00
|
|
|
FIXME("Can't handle WINED3D_BLT_DO_NOT_WAIT flag.\n");
|
2013-09-02 09:45:42 +02:00
|
|
|
}
|
|
|
|
|
2017-04-24 23:31:31 +02:00
|
|
|
flags &= ~(WINED3D_BLT_SYNCHRONOUS | WINED3D_BLT_DO_NOT_WAIT | WINED3D_BLT_WAIT);
|
|
|
|
|
2013-09-02 09:45:42 +02:00
|
|
|
if (flags & ~simple_blit)
|
|
|
|
{
|
2019-08-13 22:02:11 +02:00
|
|
|
WARN_(d3d_perf)("Using CPU fallback for complex blit (%#x).\n", flags);
|
|
|
|
goto cpu;
|
2013-09-02 09:45:42 +02:00
|
|
|
}
|
|
|
|
|
2017-03-29 23:17:30 +02:00
|
|
|
src_swapchain = src_texture->swapchain;
|
2016-03-06 20:59:49 +01:00
|
|
|
dst_swapchain = dst_texture->swapchain;
|
2013-09-02 09:45:42 +02:00
|
|
|
|
2019-08-13 22:02:13 +02:00
|
|
|
if (src_swapchain && dst_swapchain && src_swapchain != dst_swapchain
|
|
|
|
&& (wined3d_settings.offscreen_rendering_mode != ORM_FBO
|
|
|
|
|| src_texture == src_swapchain->front_buffer))
|
2013-09-02 09:45:42 +02:00
|
|
|
{
|
2019-08-13 22:02:13 +02:00
|
|
|
/* TODO: We could support cross-swapchain blits by first downloading
|
|
|
|
* the source to a texture. */
|
2019-08-13 22:02:12 +02:00
|
|
|
FIXME("Cross-swapchain blit not supported.\n");
|
|
|
|
return WINED3DERR_INVALIDCALL;
|
2013-09-02 09:45:42 +02:00
|
|
|
}
|
|
|
|
|
2018-03-07 08:26:42 +01:00
|
|
|
scale = src_box->right - src_box->left != dst_box->right - dst_box->left
|
|
|
|
|| src_box->bottom - src_box->top != dst_box->bottom - dst_box->top;
|
2017-03-29 23:17:30 +02:00
|
|
|
convert = src_texture->resource.format->id != dst_texture->resource.format->id;
|
2018-02-12 18:46:18 +01:00
|
|
|
resolve = src_texture->resource.multisample_type != dst_texture->resource.multisample_type;
|
2021-04-19 11:16:59 +02:00
|
|
|
if (resolve)
|
|
|
|
{
|
|
|
|
resolve_typeless = (wined3d_format_is_typeless(src_texture->resource.format)
|
|
|
|
|| wined3d_format_is_typeless(dst_texture->resource.format))
|
|
|
|
&& (src_texture->resource.format->typeless_id == dst_texture->resource.format->typeless_id);
|
|
|
|
if (resolve_typeless && !resolve_format)
|
|
|
|
WARN("Resolve format for typeless resolve not specified.\n");
|
|
|
|
}
|
2013-09-02 09:45:42 +02:00
|
|
|
|
2020-06-03 13:10:11 +02:00
|
|
|
dst_ds = dst_texture->resource.format->depth_size || dst_texture->resource.format->stencil_size;
|
|
|
|
src_ds = src_texture->resource.format->depth_size || src_texture->resource.format->stencil_size;
|
2013-09-02 09:45:42 +02:00
|
|
|
|
2020-06-03 13:10:11 +02:00
|
|
|
if (src_ds || dst_ds)
|
2013-09-02 09:45:42 +02:00
|
|
|
{
|
2017-03-30 23:15:31 +02:00
|
|
|
TRACE("Depth/stencil blit.\n");
|
|
|
|
|
2018-02-01 00:37:33 +01:00
|
|
|
if (dst_texture->resource.access & WINED3D_RESOURCE_ACCESS_GPU)
|
2017-04-04 09:07:43 +02:00
|
|
|
dst_location = dst_texture->resource.draw_binding;
|
2018-02-01 00:37:33 +01:00
|
|
|
else
|
|
|
|
dst_location = dst_texture->resource.map_binding;
|
2017-04-03 07:39:46 +02:00
|
|
|
|
2018-09-02 01:31:37 +02:00
|
|
|
if ((flags & WINED3D_BLT_RAW) || (!scale && !convert && !resolve))
|
|
|
|
blit_op = WINED3D_BLIT_OP_RAW_BLIT;
|
|
|
|
else
|
|
|
|
blit_op = WINED3D_BLIT_OP_DEPTH_BLIT;
|
|
|
|
|
2017-04-04 09:07:43 +02:00
|
|
|
context = context_acquire(device, dst_texture, dst_sub_resource_idx);
|
2018-09-02 01:31:37 +02:00
|
|
|
valid_locations = device->blitter->ops->blitter_blit(device->blitter, blit_op, context,
|
2018-03-13 11:23:01 +01:00
|
|
|
src_texture, src_sub_resource_idx, src_texture->resource.draw_binding, &src_rect,
|
2021-03-31 12:27:37 +02:00
|
|
|
dst_texture, dst_sub_resource_idx, dst_location, &dst_rect, NULL, filter, resolve_format);
|
2017-04-04 09:07:43 +02:00
|
|
|
context_release(context);
|
2017-03-30 23:15:31 +02:00
|
|
|
|
2017-09-06 01:39:18 +02:00
|
|
|
wined3d_texture_validate_location(dst_texture, dst_sub_resource_idx, valid_locations);
|
|
|
|
wined3d_texture_invalidate_location(dst_texture, dst_sub_resource_idx, ~valid_locations);
|
2017-03-30 23:15:31 +02:00
|
|
|
|
2017-04-04 09:07:43 +02:00
|
|
|
return WINED3D_OK;
|
2013-09-02 09:45:42 +02:00
|
|
|
}
|
2015-04-14 11:16:26 +02:00
|
|
|
|
2017-04-04 09:07:44 +02:00
|
|
|
TRACE("Colour blit.\n");
|
2017-03-29 23:17:29 +02:00
|
|
|
|
2017-04-04 09:07:44 +02:00
|
|
|
/* In principle this would apply to depth blits as well, but we don't
|
|
|
|
* implement those in the CPU blitter at the moment. */
|
|
|
|
if ((dst_sub_resource->locations & dst_texture->resource.map_binding)
|
|
|
|
&& (src_sub_resource->locations & src_texture->resource.map_binding))
|
|
|
|
{
|
|
|
|
if (scale)
|
|
|
|
TRACE("Not doing sysmem blit because of scaling.\n");
|
|
|
|
else if (convert)
|
|
|
|
TRACE("Not doing sysmem blit because of format conversion.\n");
|
|
|
|
else
|
|
|
|
goto cpu;
|
|
|
|
}
|
2013-09-02 09:45:42 +02:00
|
|
|
|
2017-04-04 09:07:44 +02:00
|
|
|
blit_op = WINED3D_BLIT_OP_COLOR_BLIT;
|
|
|
|
if (flags & WINED3D_BLT_SRC_CKEY_OVERRIDE)
|
|
|
|
{
|
|
|
|
colour_key = &fx->src_color_key;
|
|
|
|
blit_op = WINED3D_BLIT_OP_COLOR_BLIT_CKEY;
|
|
|
|
}
|
|
|
|
else if (flags & WINED3D_BLT_SRC_CKEY)
|
|
|
|
{
|
|
|
|
colour_key = &src_texture->async.src_blt_color_key;
|
|
|
|
blit_op = WINED3D_BLIT_OP_COLOR_BLIT_CKEY;
|
|
|
|
}
|
|
|
|
else if (flags & WINED3D_BLT_ALPHA_TEST)
|
|
|
|
{
|
|
|
|
blit_op = WINED3D_BLIT_OP_COLOR_BLIT_ALPHATEST;
|
|
|
|
}
|
2017-09-15 15:12:23 +02:00
|
|
|
else if ((src_sub_resource->locations & surface_simple_locations)
|
2020-06-02 01:17:01 +02:00
|
|
|
&& !(dst_sub_resource->locations & surface_simple_locations)
|
|
|
|
&& (dst_texture->resource.access & WINED3D_RESOURCE_ACCESS_GPU))
|
2017-04-04 09:07:44 +02:00
|
|
|
{
|
|
|
|
/* Upload */
|
|
|
|
if (scale)
|
|
|
|
TRACE("Not doing upload because of scaling.\n");
|
|
|
|
else if (convert)
|
|
|
|
TRACE("Not doing upload because of format conversion.\n");
|
2018-01-05 18:53:12 +01:00
|
|
|
else if (dst_texture->resource.format->conv_byte_count)
|
2017-09-06 01:39:19 +02:00
|
|
|
TRACE("Not doing upload because the destination format needs conversion.\n");
|
2017-04-04 09:07:44 +02:00
|
|
|
else
|
2017-03-29 23:17:29 +02:00
|
|
|
{
|
2018-04-16 15:29:28 +02:00
|
|
|
wined3d_texture_upload_from_texture(dst_texture, dst_sub_resource_idx, dst_box->left,
|
|
|
|
dst_box->top, dst_box->front, src_texture, src_sub_resource_idx, src_box);
|
|
|
|
if (!wined3d_resource_is_offscreen(&dst_texture->resource))
|
2017-04-04 09:07:44 +02:00
|
|
|
{
|
2018-04-16 15:29:28 +02:00
|
|
|
context = context_acquire(device, dst_texture, dst_sub_resource_idx);
|
|
|
|
wined3d_texture_load_location(dst_texture, dst_sub_resource_idx,
|
|
|
|
context, dst_texture->resource.draw_binding);
|
|
|
|
context_release(context);
|
2013-09-02 09:45:42 +02:00
|
|
|
}
|
2018-04-16 15:29:28 +02:00
|
|
|
return WINED3D_OK;
|
2017-03-29 23:17:29 +02:00
|
|
|
}
|
2017-04-04 09:07:44 +02:00
|
|
|
}
|
2018-10-04 08:16:44 +02:00
|
|
|
else if (!(src_sub_resource->locations & surface_simple_locations)
|
2018-11-20 13:20:44 +01:00
|
|
|
&& (dst_sub_resource->locations & dst_texture->resource.map_binding)
|
|
|
|
&& !(dst_texture->resource.access & WINED3D_RESOURCE_ACCESS_GPU))
|
2018-10-04 08:16:44 +02:00
|
|
|
{
|
|
|
|
/* Download */
|
|
|
|
if (scale)
|
|
|
|
TRACE("Not doing download because of scaling.\n");
|
|
|
|
else if (convert)
|
|
|
|
TRACE("Not doing download because of format conversion.\n");
|
|
|
|
else if (src_texture->resource.format->conv_byte_count)
|
|
|
|
TRACE("Not doing download because the source format needs conversion.\n");
|
2019-08-19 13:54:27 +02:00
|
|
|
else if (!(src_texture->flags & WINED3D_TEXTURE_DOWNLOADABLE))
|
|
|
|
TRACE("Not doing download because texture is not downloadable.\n");
|
2020-05-28 20:02:15 +02:00
|
|
|
else if (!wined3d_texture_is_full_rect(src_texture, src_sub_resource_idx % src_texture->level_count, &src_rect))
|
2018-10-04 08:16:44 +02:00
|
|
|
TRACE("Not doing download because of partial download (src).\n");
|
2020-05-28 20:02:15 +02:00
|
|
|
else if (!wined3d_texture_is_full_rect(dst_texture, dst_sub_resource_idx % dst_texture->level_count, &dst_rect))
|
2018-10-04 08:16:44 +02:00
|
|
|
TRACE("Not doing download because of partial download (dst).\n");
|
|
|
|
else
|
|
|
|
{
|
|
|
|
wined3d_texture_download_from_texture(dst_texture, dst_sub_resource_idx, src_texture,
|
|
|
|
src_sub_resource_idx);
|
|
|
|
return WINED3D_OK;
|
|
|
|
}
|
|
|
|
}
|
2017-04-04 09:07:44 +02:00
|
|
|
else if (dst_swapchain && dst_swapchain->back_buffers
|
|
|
|
&& dst_texture == dst_swapchain->front_buffer
|
|
|
|
&& src_texture == dst_swapchain->back_buffers[0])
|
|
|
|
{
|
|
|
|
/* Use present for back -> front blits. The idea behind this is that
|
|
|
|
* present is potentially faster than a blit, in particular when FBO
|
|
|
|
* blits aren't available. Some ddraw applications like Half-Life and
|
|
|
|
* Prince of Persia 3D use Blt() from the backbuffer to the
|
|
|
|
* frontbuffer instead of doing a Flip(). D3d8 and d3d9 applications
|
|
|
|
* can't blit directly to the frontbuffer. */
|
2019-07-29 13:30:55 +02:00
|
|
|
enum wined3d_swap_effect swap_effect = dst_swapchain->state.desc.swap_effect;
|
2013-09-02 09:45:42 +02:00
|
|
|
|
2017-04-04 09:07:44 +02:00
|
|
|
TRACE("Using present for backbuffer -> frontbuffer blit.\n");
|
2017-04-03 07:39:46 +02:00
|
|
|
|
2017-04-04 09:07:44 +02:00
|
|
|
/* Set the swap effect to COPY, we don't want the backbuffer to become
|
|
|
|
* undefined. */
|
2019-07-29 13:30:55 +02:00
|
|
|
dst_swapchain->state.desc.swap_effect = WINED3D_SWAP_EFFECT_COPY;
|
2018-03-22 08:48:32 +01:00
|
|
|
wined3d_swapchain_present(dst_swapchain, NULL, NULL,
|
|
|
|
dst_swapchain->win_handle, dst_swapchain->swap_interval, 0);
|
2019-07-29 13:30:55 +02:00
|
|
|
dst_swapchain->state.desc.swap_effect = swap_effect;
|
2017-03-17 13:33:19 +01:00
|
|
|
|
2017-04-04 09:07:43 +02:00
|
|
|
return WINED3D_OK;
|
2013-09-02 09:45:42 +02:00
|
|
|
}
|
2018-10-04 08:16:44 +02:00
|
|
|
|
|
|
|
if ((flags & WINED3D_BLT_RAW) || (blit_op == WINED3D_BLIT_OP_COLOR_BLIT && !scale && !convert && !resolve))
|
2017-11-15 22:13:00 +01:00
|
|
|
blit_op = WINED3D_BLIT_OP_RAW_BLIT;
|
2013-09-02 09:45:42 +02:00
|
|
|
|
2020-03-12 10:49:50 +01:00
|
|
|
context = context_acquire(device, dst_texture, dst_sub_resource_idx);
|
|
|
|
|
2021-04-19 11:16:59 +02:00
|
|
|
if (src_texture->resource.multisample_type != WINED3D_MULTISAMPLE_NONE && !resolve_typeless
|
2020-03-12 10:49:50 +01:00
|
|
|
&& ((scale && !context->d3d_info->scaled_resolve)
|
2020-05-28 20:02:18 +02:00
|
|
|
|| convert || !wined3d_is_colour_blit(blit_op)))
|
2020-03-12 10:49:48 +01:00
|
|
|
src_location = WINED3D_LOCATION_RB_RESOLVED;
|
|
|
|
else
|
|
|
|
src_location = src_texture->resource.draw_binding;
|
|
|
|
|
2020-03-12 10:49:49 +01:00
|
|
|
if (!(dst_texture->resource.access & WINED3D_RESOURCE_ACCESS_GPU))
|
2018-02-01 00:37:33 +01:00
|
|
|
dst_location = dst_texture->resource.map_binding;
|
2020-03-12 10:49:49 +01:00
|
|
|
else if (dst_texture->resource.multisample_type != WINED3D_MULTISAMPLE_NONE
|
2020-05-28 20:02:17 +02:00
|
|
|
&& (scale || convert || !wined3d_is_colour_blit(blit_op)))
|
2020-03-12 10:49:49 +01:00
|
|
|
dst_location = WINED3D_LOCATION_RB_RESOLVED;
|
|
|
|
else
|
|
|
|
dst_location = dst_texture->resource.draw_binding;
|
2017-04-04 09:07:44 +02:00
|
|
|
|
2017-09-06 01:39:18 +02:00
|
|
|
valid_locations = device->blitter->ops->blitter_blit(device->blitter, blit_op, context,
|
2020-03-12 10:49:48 +01:00
|
|
|
src_texture, src_sub_resource_idx, src_location, &src_rect,
|
2021-03-31 12:27:37 +02:00
|
|
|
dst_texture, dst_sub_resource_idx, dst_location, &dst_rect, colour_key, filter, resolve_format);
|
2020-03-12 10:49:50 +01:00
|
|
|
|
2017-04-04 09:07:44 +02:00
|
|
|
context_release(context);
|
|
|
|
|
2017-09-06 01:39:18 +02:00
|
|
|
wined3d_texture_validate_location(dst_texture, dst_sub_resource_idx, valid_locations);
|
|
|
|
wined3d_texture_invalidate_location(dst_texture, dst_sub_resource_idx, ~valid_locations);
|
2017-04-04 09:07:44 +02:00
|
|
|
|
|
|
|
return WINED3D_OK;
|
|
|
|
|
2013-09-02 09:45:42 +02:00
|
|
|
cpu:
|
2018-03-07 08:26:42 +01:00
|
|
|
return surface_cpu_blt(dst_texture, dst_sub_resource_idx, dst_box,
|
|
|
|
src_texture, src_sub_resource_idx, src_box, flags, fx, filter);
|
2013-09-02 09:45:42 +02:00
|
|
|
}
|