2018-12-28 12:41:38 +01:00
|
|
|
/* RetroArch - A frontend for libretro.
|
2014-01-01 01:50:59 +01:00
|
|
|
* Copyright (C) 2010-2014 - Hans-Kristian Arntzen
|
2017-01-22 13:40:32 +01:00
|
|
|
* Copyright (C) 2011-2017 - Daniel De Matteis
|
2014-01-01 01:50:59 +01:00
|
|
|
* Copyright (C) 2012-2014 - OV2
|
2015-05-20 17:28:12 -05:00
|
|
|
*
|
2012-10-26 21:09:30 +02:00
|
|
|
* RetroArch is free software: you can redistribute it and/or modify it under the terms
|
|
|
|
* of the GNU General Public License as published by the Free Software Found-
|
|
|
|
* ation, either version 3 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* RetroArch 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 General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along with RetroArch.
|
|
|
|
* If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2018-04-22 14:27:39 +02:00
|
|
|
#define CINTERFACE
|
|
|
|
|
2014-09-11 20:31:37 +02:00
|
|
|
#ifdef _XBOX
|
|
|
|
#include <xtl.h>
|
|
|
|
#include <xgraphics.h>
|
|
|
|
#endif
|
|
|
|
|
2015-07-11 19:47:20 +02:00
|
|
|
#include <formats/image.h>
|
2015-09-05 14:10:16 +02:00
|
|
|
#include <compat/strl.h>
|
|
|
|
#include <compat/posix_string.h>
|
|
|
|
#include <file/file_path.h>
|
2016-01-20 04:14:55 +01:00
|
|
|
#include <string/stdstring.h>
|
2017-06-28 04:41:38 +02:00
|
|
|
#include <retro_math.h>
|
2015-07-11 19:47:20 +02:00
|
|
|
|
2018-01-25 15:30:48 +01:00
|
|
|
#include <d3d9.h>
|
|
|
|
|
2019-07-21 12:13:04 +02:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "../../config.h"
|
|
|
|
#endif
|
|
|
|
|
2021-05-18 22:15:04 +02:00
|
|
|
#include <defines/d3d_defines.h>
|
2018-01-25 11:50:07 +01:00
|
|
|
#include "../common/d3d_common.h"
|
2018-03-03 15:28:58 +01:00
|
|
|
#include "../common/d3d9_common.h"
|
2016-03-05 07:27:48 +01:00
|
|
|
#include "../video_coord_array.h"
|
2016-09-05 18:43:06 +02:00
|
|
|
#include "../../configuration.h"
|
2015-04-11 21:57:03 +02:00
|
|
|
#include "../../dynamic.h"
|
2018-03-02 17:30:21 +01:00
|
|
|
#include "../../ui/ui_companion_driver.h"
|
2019-02-15 15:58:52 -05:00
|
|
|
#include "../../frontend/frontend_driver.h"
|
2014-03-07 21:55:18 +01:00
|
|
|
|
2015-12-20 21:59:57 +01:00
|
|
|
#ifdef HAVE_THREADS
|
|
|
|
#include "../video_thread_wrapper.h"
|
|
|
|
#endif
|
|
|
|
|
2015-04-09 05:16:02 +02:00
|
|
|
#include "../common/win32_common.h"
|
2014-09-11 20:59:52 +02:00
|
|
|
|
2018-03-02 17:05:30 +01:00
|
|
|
#ifdef _XBOX
|
|
|
|
#define D3D9_PRESENTATIONINTERVAL D3DRS_PRESENTINTERVAL
|
2014-09-11 20:59:52 +02:00
|
|
|
#endif
|
2014-01-09 18:44:25 +01:00
|
|
|
|
2018-03-02 17:30:21 +01:00
|
|
|
#define FS_PRESENTINTERVAL(pp) ((pp)->PresentationInterval)
|
|
|
|
|
2015-12-05 13:30:37 +01:00
|
|
|
#ifdef HAVE_MENU
|
|
|
|
#include "../../menu/menu_driver.h"
|
2019-02-21 17:09:08 +01:00
|
|
|
#endif
|
2020-02-17 21:28:42 +01:00
|
|
|
#ifdef HAVE_GFX_WIDGETS
|
|
|
|
#include "../gfx_widgets.h"
|
2015-12-05 13:30:37 +01:00
|
|
|
#endif
|
|
|
|
|
2017-01-19 17:20:42 +01:00
|
|
|
#include "../font_driver.h"
|
|
|
|
|
2016-05-08 05:29:10 +02:00
|
|
|
#include "../../core.h"
|
2015-11-23 12:14:53 +01:00
|
|
|
#include "../../verbosity.h"
|
2018-01-29 22:11:08 -05:00
|
|
|
#include "../../retroarch.h"
|
2015-04-06 01:10:39 +02:00
|
|
|
|
2018-12-28 12:41:38 +01:00
|
|
|
#ifdef __WINRT__
|
|
|
|
#error "UWP does not support D3D9"
|
|
|
|
#endif
|
|
|
|
|
2019-06-24 23:40:50 +02:00
|
|
|
/* Temporary workaround for d3d9 not being able to poll flags during init */
|
|
|
|
static gfx_ctx_driver_t d3d9_fake_context;
|
|
|
|
static uint32_t d3d9_get_flags(void *data);
|
2020-03-07 17:04:06 +01:00
|
|
|
static bool d3d9_set_shader(void *data,
|
|
|
|
enum rarch_shader_type type, const char *path);
|
2019-06-24 23:40:50 +02:00
|
|
|
|
2018-01-25 04:12:16 +01:00
|
|
|
static LPDIRECT3D9 g_pD3D9;
|
2019-06-25 10:54:31 +02:00
|
|
|
static enum rarch_shader_type supported_shader_type = RARCH_SHADER_NONE;
|
2016-01-07 01:23:52 +01:00
|
|
|
|
2018-03-02 17:00:11 +01:00
|
|
|
void *dinput;
|
|
|
|
|
2018-05-03 22:03:12 +02:00
|
|
|
static bool d3d9_set_resize(d3d9_video_t *d3d,
|
2018-03-02 16:38:57 +01:00
|
|
|
unsigned new_width, unsigned new_height)
|
|
|
|
{
|
|
|
|
/* No changes? */
|
|
|
|
if ( (new_width == d3d->video_info.width)
|
|
|
|
&& (new_height == d3d->video_info.height))
|
|
|
|
return false;
|
|
|
|
|
2018-05-13 18:51:05 +02:00
|
|
|
RARCH_LOG("[D3D9]: Resize %ux%u.\n", new_width, new_height);
|
2018-03-02 16:38:57 +01:00
|
|
|
d3d->video_info.width = new_width;
|
|
|
|
d3d->video_info.height = new_height;
|
2020-01-31 03:47:50 +01:00
|
|
|
video_driver_set_size(new_width, new_height);
|
2018-03-02 16:38:57 +01:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-05-13 06:03:26 +02:00
|
|
|
extern d3d9_renderchain_driver_t cg_d3d9_renderchain;
|
|
|
|
extern d3d9_renderchain_driver_t hlsl_d3d9_renderchain;
|
2018-02-16 11:24:10 +01:00
|
|
|
|
|
|
|
static bool renderchain_d3d_init_first(
|
|
|
|
enum gfx_ctx_api api,
|
2018-05-13 06:03:26 +02:00
|
|
|
const d3d9_renderchain_driver_t **renderchain_driver,
|
2018-02-16 11:24:10 +01:00
|
|
|
void **renderchain_handle)
|
|
|
|
{
|
|
|
|
switch (api)
|
|
|
|
{
|
|
|
|
case GFX_CTX_DIRECT3D9_API:
|
|
|
|
{
|
2019-06-25 10:54:31 +02:00
|
|
|
static const d3d9_renderchain_driver_t *renderchain_d3d_drivers[] =
|
|
|
|
{
|
2018-02-16 11:24:10 +01:00
|
|
|
#if defined(_WIN32) && defined(HAVE_CG)
|
|
|
|
&cg_d3d9_renderchain,
|
|
|
|
#endif
|
|
|
|
#if defined(_WIN32) && defined(HAVE_HLSL)
|
|
|
|
&hlsl_d3d9_renderchain,
|
|
|
|
#endif
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
unsigned i;
|
|
|
|
|
|
|
|
for (i = 0; renderchain_d3d_drivers[i]; i++)
|
|
|
|
{
|
|
|
|
void *data = renderchain_d3d_drivers[i]->chain_new();
|
|
|
|
|
|
|
|
if (!data)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
*renderchain_driver = renderchain_d3d_drivers[i];
|
|
|
|
*renderchain_handle = data;
|
2019-06-25 10:54:31 +02:00
|
|
|
|
|
|
|
if (string_is_equal(renderchain_d3d_drivers[i]->ident, "cg_d3d9"))
|
|
|
|
supported_shader_type = RARCH_SHADER_CG;
|
|
|
|
else if (string_is_equal(renderchain_d3d_drivers[i]->ident, "hlsl_d3d9"))
|
|
|
|
supported_shader_type = RARCH_SHADER_HLSL;
|
|
|
|
|
2018-02-16 11:24:10 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case GFX_CTX_NONE:
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-05-13 18:01:09 +02:00
|
|
|
static void d3d9_log_info(const struct LinkInfo *info)
|
|
|
|
{
|
2018-05-13 18:51:05 +02:00
|
|
|
RARCH_LOG("[D3D9]: Render pass info:\n");
|
2018-05-13 18:01:09 +02:00
|
|
|
RARCH_LOG("\tTexture width: %u\n", info->tex_w);
|
|
|
|
RARCH_LOG("\tTexture height: %u\n", info->tex_h);
|
|
|
|
|
|
|
|
RARCH_LOG("\tScale type (X): ");
|
|
|
|
|
|
|
|
switch (info->pass->fbo.type_x)
|
|
|
|
{
|
|
|
|
case RARCH_SCALE_INPUT:
|
|
|
|
RARCH_LOG("Relative @ %fx\n", info->pass->fbo.scale_x);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case RARCH_SCALE_VIEWPORT:
|
|
|
|
RARCH_LOG("Viewport @ %fx\n", info->pass->fbo.scale_x);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case RARCH_SCALE_ABSOLUTE:
|
|
|
|
RARCH_LOG("Absolute @ %u px\n", info->pass->fbo.abs_x);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
RARCH_LOG("\tScale type (Y): ");
|
|
|
|
|
|
|
|
switch (info->pass->fbo.type_y)
|
|
|
|
{
|
|
|
|
case RARCH_SCALE_INPUT:
|
|
|
|
RARCH_LOG("Relative @ %fx\n", info->pass->fbo.scale_y);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case RARCH_SCALE_VIEWPORT:
|
|
|
|
RARCH_LOG("Viewport @ %fx\n", info->pass->fbo.scale_y);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case RARCH_SCALE_ABSOLUTE:
|
|
|
|
RARCH_LOG("Absolute @ %u px\n", info->pass->fbo.abs_y);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
RARCH_LOG("\tBilinear filter: %s\n",
|
|
|
|
info->pass->filter == RARCH_FILTER_LINEAR ? "true" : "false");
|
|
|
|
}
|
|
|
|
|
2020-03-09 16:15:53 +01:00
|
|
|
static bool d3d9_init_chain(d3d9_video_t *d3d,
|
|
|
|
unsigned input_scale,
|
|
|
|
bool rgb32)
|
2016-01-09 04:12:33 +01:00
|
|
|
{
|
2020-03-09 16:15:53 +01:00
|
|
|
unsigned i = 0;
|
2018-01-19 03:52:32 +01:00
|
|
|
struct LinkInfo link_info;
|
2020-06-13 08:37:26 +02:00
|
|
|
#ifndef _XBOX
|
2016-01-09 04:12:33 +01:00
|
|
|
unsigned current_width, current_height, out_width, out_height;
|
2020-06-13 08:37:26 +02:00
|
|
|
#endif
|
2016-01-09 04:12:33 +01:00
|
|
|
|
|
|
|
/* Setup information for first pass. */
|
2018-01-19 03:52:32 +01:00
|
|
|
link_info.pass = NULL;
|
2020-03-09 16:15:53 +01:00
|
|
|
link_info.tex_w = input_scale * RARCH_SCALE_BASE;
|
|
|
|
link_info.tex_h = input_scale * RARCH_SCALE_BASE;
|
2016-01-09 04:12:33 +01:00
|
|
|
link_info.pass = &d3d->shader.pass[0];
|
|
|
|
|
2018-01-23 04:25:37 +01:00
|
|
|
if (!renderchain_d3d_init_first(GFX_CTX_DIRECT3D9_API,
|
2018-01-23 02:55:33 +01:00
|
|
|
&d3d->renderchain_driver,
|
|
|
|
&d3d->renderchain_data))
|
2016-01-09 04:12:33 +01:00
|
|
|
{
|
2019-06-24 23:40:50 +02:00
|
|
|
RARCH_ERR("[D3D9]: Renderchain could not be initialized.\n");
|
|
|
|
return false;
|
2016-01-09 04:12:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!d3d->renderchain_driver || !d3d->renderchain_data)
|
2019-06-24 23:40:50 +02:00
|
|
|
return false;
|
2016-01-09 04:12:33 +01:00
|
|
|
|
|
|
|
if (
|
|
|
|
!d3d->renderchain_driver->init(
|
|
|
|
d3d,
|
|
|
|
d3d->dev, &d3d->final_viewport, &link_info,
|
2020-03-09 16:15:53 +01:00
|
|
|
rgb32)
|
2016-01-09 04:12:33 +01:00
|
|
|
)
|
|
|
|
{
|
2018-05-13 18:51:05 +02:00
|
|
|
RARCH_ERR("[D3D9]: Failed to init render chain.\n");
|
2016-01-09 04:12:33 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-05-13 18:51:05 +02:00
|
|
|
RARCH_LOG("[D3D9]: Renderchain driver: %s\n", d3d->renderchain_driver->ident);
|
2018-05-13 18:01:09 +02:00
|
|
|
d3d9_log_info(&link_info);
|
2016-01-09 04:12:33 +01:00
|
|
|
|
|
|
|
#ifndef _XBOX
|
|
|
|
current_width = link_info.tex_w;
|
|
|
|
current_height = link_info.tex_h;
|
|
|
|
out_width = 0;
|
|
|
|
out_height = 0;
|
|
|
|
|
|
|
|
for (i = 1; i < d3d->shader.passes; i++)
|
|
|
|
{
|
2018-05-14 21:32:14 +02:00
|
|
|
d3d9_convert_geometry(
|
|
|
|
&link_info,
|
2016-01-09 04:12:33 +01:00
|
|
|
&out_width, &out_height,
|
|
|
|
current_width, current_height, &d3d->final_viewport);
|
|
|
|
|
|
|
|
link_info.pass = &d3d->shader.pass[i];
|
|
|
|
link_info.tex_w = next_pow2(out_width);
|
|
|
|
link_info.tex_h = next_pow2(out_height);
|
|
|
|
|
2020-03-09 16:15:53 +01:00
|
|
|
current_width = out_width;
|
|
|
|
current_height = out_height;
|
2016-01-09 04:12:33 +01:00
|
|
|
|
2016-08-02 01:42:36 +02:00
|
|
|
if (!d3d->renderchain_driver->add_pass(
|
|
|
|
d3d->renderchain_data, &link_info))
|
2016-01-09 04:12:33 +01:00
|
|
|
{
|
2018-05-13 18:51:05 +02:00
|
|
|
RARCH_ERR("[D3D9]: Failed to add pass.\n");
|
2016-01-09 04:12:33 +01:00
|
|
|
return false;
|
|
|
|
}
|
2018-05-13 18:01:09 +02:00
|
|
|
d3d9_log_info(&link_info);
|
2016-01-09 04:12:33 +01:00
|
|
|
}
|
2016-10-20 05:36:02 +02:00
|
|
|
#endif
|
2016-01-09 04:12:33 +01:00
|
|
|
|
2017-11-06 19:39:21 +01:00
|
|
|
if (d3d->renderchain_driver)
|
2016-01-09 04:12:33 +01:00
|
|
|
{
|
2017-11-06 19:39:21 +01:00
|
|
|
if (d3d->renderchain_driver->add_lut)
|
|
|
|
{
|
|
|
|
unsigned i;
|
|
|
|
settings_t *settings = config_get_ptr();
|
2020-02-18 14:51:40 +01:00
|
|
|
bool video_smooth = settings->bools.video_smooth;
|
2017-11-06 19:39:21 +01:00
|
|
|
|
|
|
|
for (i = 0; i < d3d->shader.luts; i++)
|
|
|
|
{
|
|
|
|
if (!d3d->renderchain_driver->add_lut(
|
|
|
|
d3d->renderchain_data,
|
|
|
|
d3d->shader.lut[i].id, d3d->shader.lut[i].path,
|
2020-02-18 14:51:40 +01:00
|
|
|
d3d->shader.lut[i].filter == RARCH_FILTER_UNSPEC
|
|
|
|
? video_smooth
|
|
|
|
: (d3d->shader.lut[i].filter == RARCH_FILTER_LINEAR)))
|
2017-11-06 19:39:21 +01:00
|
|
|
{
|
2018-05-13 18:51:05 +02:00
|
|
|
RARCH_ERR("[D3D9]: Failed to init LUTs.\n");
|
2017-11-06 19:39:21 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-01-09 04:12:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2014-09-13 08:06:01 +02:00
|
|
|
|
2018-05-03 22:03:12 +02:00
|
|
|
static bool d3d9_init_singlepass(d3d9_video_t *d3d)
|
2016-01-09 04:10:36 +01:00
|
|
|
{
|
2017-10-02 07:48:57 +02:00
|
|
|
struct video_shader_pass *pass = NULL;
|
2016-01-09 04:10:36 +01:00
|
|
|
|
|
|
|
if (!d3d)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
memset(&d3d->shader, 0, sizeof(d3d->shader));
|
|
|
|
d3d->shader.passes = 1;
|
|
|
|
|
2017-10-02 07:48:57 +02:00
|
|
|
pass = (struct video_shader_pass*)
|
2016-08-02 01:42:36 +02:00
|
|
|
&d3d->shader.pass[0];
|
2016-01-09 04:10:36 +01:00
|
|
|
|
|
|
|
pass->fbo.valid = true;
|
|
|
|
pass->fbo.scale_y = 1.0;
|
|
|
|
pass->fbo.type_y = RARCH_SCALE_VIEWPORT;
|
|
|
|
pass->fbo.scale_x = pass->fbo.scale_y;
|
|
|
|
pass->fbo.type_x = pass->fbo.type_y;
|
2017-10-02 01:38:06 +02:00
|
|
|
|
|
|
|
if (!string_is_empty(d3d->shader_path))
|
|
|
|
strlcpy(pass->source.path, d3d->shader_path,
|
|
|
|
sizeof(pass->source.path));
|
2016-01-09 04:10:36 +01:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-05-03 22:03:12 +02:00
|
|
|
static bool d3d9_init_multipass(d3d9_video_t *d3d, const char *shader_path)
|
2016-01-09 04:11:20 +01:00
|
|
|
{
|
|
|
|
unsigned i;
|
2018-01-07 20:21:08 +01:00
|
|
|
bool use_extra_pass = false;
|
2017-10-02 07:48:57 +02:00
|
|
|
struct video_shader_pass *pass = NULL;
|
2016-01-09 04:11:20 +01:00
|
|
|
|
|
|
|
memset(&d3d->shader, 0, sizeof(d3d->shader));
|
2018-01-07 20:21:08 +01:00
|
|
|
|
2020-12-26 21:09:27 -05:00
|
|
|
if (!video_shader_load_preset_into_shader(shader_path, &d3d->shader))
|
2016-01-09 04:11:20 +01:00
|
|
|
{
|
2019-06-25 10:54:31 +02:00
|
|
|
RARCH_ERR("[D3D9]: Failed to parse shader preset.\n");
|
2016-01-09 04:11:20 +01:00
|
|
|
return false;
|
|
|
|
}
|
2018-01-07 20:21:08 +01:00
|
|
|
|
2018-05-13 18:51:05 +02:00
|
|
|
RARCH_LOG("[D3D9]: Found %u shaders.\n", d3d->shader.passes);
|
2016-01-09 04:11:20 +01:00
|
|
|
|
|
|
|
for (i = 0; i < d3d->shader.passes; i++)
|
|
|
|
{
|
|
|
|
if (d3d->shader.pass[i].fbo.valid)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
d3d->shader.pass[i].fbo.scale_y = 1.0f;
|
|
|
|
d3d->shader.pass[i].fbo.scale_x = 1.0f;
|
|
|
|
d3d->shader.pass[i].fbo.type_x = RARCH_SCALE_INPUT;
|
|
|
|
d3d->shader.pass[i].fbo.type_y = RARCH_SCALE_INPUT;
|
|
|
|
}
|
|
|
|
|
|
|
|
use_extra_pass = d3d->shader.passes < GFX_MAX_SHADERS &&
|
|
|
|
d3d->shader.pass[d3d->shader.passes - 1].fbo.valid;
|
|
|
|
|
|
|
|
if (use_extra_pass)
|
|
|
|
{
|
|
|
|
d3d->shader.passes++;
|
2017-10-02 07:48:57 +02:00
|
|
|
pass = (struct video_shader_pass*)
|
2016-01-09 04:11:20 +01:00
|
|
|
&d3d->shader.pass[d3d->shader.passes - 1];
|
|
|
|
|
2018-01-07 20:21:08 +01:00
|
|
|
pass->fbo.scale_x = 1.0f;
|
|
|
|
pass->fbo.scale_y = 1.0f;
|
|
|
|
pass->fbo.type_x = RARCH_SCALE_VIEWPORT;
|
|
|
|
pass->fbo.type_y = RARCH_SCALE_VIEWPORT;
|
2016-01-09 04:11:20 +01:00
|
|
|
pass->filter = RARCH_FILTER_UNSPEC;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-10-02 07:48:57 +02:00
|
|
|
pass = (struct video_shader_pass*)
|
2016-01-09 04:11:20 +01:00
|
|
|
&d3d->shader.pass[d3d->shader.passes - 1];
|
|
|
|
|
2018-01-07 20:21:08 +01:00
|
|
|
pass->fbo.scale_x = 1.0f;
|
|
|
|
pass->fbo.scale_y = 1.0f;
|
|
|
|
pass->fbo.type_x = RARCH_SCALE_VIEWPORT;
|
|
|
|
pass->fbo.type_y = RARCH_SCALE_VIEWPORT;
|
2016-01-09 04:11:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-05-03 22:03:12 +02:00
|
|
|
static bool d3d9_process_shader(d3d9_video_t *d3d)
|
2016-01-09 04:10:36 +01:00
|
|
|
{
|
2018-01-07 20:21:08 +01:00
|
|
|
const char *shader_path = d3d->shader_path;
|
2019-06-25 10:54:31 +02:00
|
|
|
if (d3d && !string_is_empty(shader_path))
|
2018-01-23 06:43:03 +01:00
|
|
|
return d3d9_init_multipass(d3d, shader_path);
|
2016-01-09 04:10:36 +01:00
|
|
|
|
2018-01-23 06:43:03 +01:00
|
|
|
return d3d9_init_singlepass(d3d);
|
2016-01-09 04:10:36 +01:00
|
|
|
}
|
|
|
|
|
2018-01-23 06:43:03 +01:00
|
|
|
static void d3d9_viewport_info(void *data, struct video_viewport *vp)
|
2016-01-09 03:10:08 +01:00
|
|
|
{
|
2018-05-13 06:29:17 +02:00
|
|
|
unsigned width, height;
|
2018-05-03 22:03:12 +02:00
|
|
|
d3d9_video_t *d3d = (d3d9_video_t*)data;
|
2016-01-09 03:10:08 +01:00
|
|
|
|
2018-05-13 06:29:17 +02:00
|
|
|
if (!vp)
|
|
|
|
return;
|
|
|
|
|
|
|
|
video_driver_get_size(&width, &height);
|
|
|
|
|
2018-05-13 18:24:19 +02:00
|
|
|
vp->x = d3d->final_viewport.X;
|
|
|
|
vp->y = d3d->final_viewport.Y;
|
|
|
|
vp->width = d3d->final_viewport.Width;
|
|
|
|
vp->height = d3d->final_viewport.Height;
|
2018-05-13 06:29:17 +02:00
|
|
|
|
|
|
|
vp->full_width = width;
|
|
|
|
vp->full_height = height;
|
2016-01-09 03:10:08 +01:00
|
|
|
}
|
|
|
|
|
2019-03-18 15:19:11 +01:00
|
|
|
void d3d9_set_mvp(void *data, const void *mat_data)
|
2018-01-15 03:45:37 +01:00
|
|
|
{
|
2019-03-18 15:19:11 +01:00
|
|
|
LPDIRECT3DDEVICE9 dev = (LPDIRECT3DDEVICE9)data;
|
|
|
|
d3d9_set_vertex_shader_constantf(dev, 0, (const float*)mat_data, 4);
|
2018-01-15 03:45:37 +01:00
|
|
|
}
|
|
|
|
|
2019-07-11 01:10:00 +02:00
|
|
|
#if defined(HAVE_MENU) || defined(HAVE_OVERLAY)
|
2018-05-03 22:03:12 +02:00
|
|
|
static void d3d9_overlay_render(d3d9_video_t *d3d,
|
2020-03-09 16:15:53 +01:00
|
|
|
unsigned width,
|
|
|
|
unsigned height,
|
2018-04-24 14:47:21 +02:00
|
|
|
overlay_t *overlay, bool force_linear)
|
2016-01-09 03:10:08 +01:00
|
|
|
{
|
2018-04-24 14:47:21 +02:00
|
|
|
D3DTEXTUREFILTERTYPE filter_type;
|
2018-01-25 14:34:20 +01:00
|
|
|
LPDIRECT3DVERTEXDECLARATION9 vertex_decl;
|
2018-05-03 15:20:06 +02:00
|
|
|
LPDIRECT3DDEVICE9 dev;
|
2016-01-09 03:10:08 +01:00
|
|
|
struct video_viewport vp;
|
|
|
|
void *verts;
|
|
|
|
unsigned i;
|
2018-01-17 07:10:45 +01:00
|
|
|
Vertex vert[4];
|
2018-01-25 14:34:20 +01:00
|
|
|
D3DVERTEXELEMENT9 vElems[4] = {
|
2018-01-23 02:55:33 +01:00
|
|
|
{0, offsetof(Vertex, x), D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT,
|
|
|
|
D3DDECLUSAGE_POSITION, 0},
|
|
|
|
{0, offsetof(Vertex, u), D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT,
|
|
|
|
D3DDECLUSAGE_TEXCOORD, 0},
|
|
|
|
{0, offsetof(Vertex, color), D3DDECLTYPE_D3DCOLOR, D3DDECLMETHOD_DEFAULT,
|
|
|
|
D3DDECLUSAGE_COLOR, 0},
|
|
|
|
D3DDECL_END()
|
|
|
|
};
|
2016-01-09 03:10:08 +01:00
|
|
|
|
2016-10-20 04:51:37 +02:00
|
|
|
if (!d3d || !overlay || !overlay->tex)
|
2016-01-09 03:10:08 +01:00
|
|
|
return;
|
|
|
|
|
2018-05-03 22:06:04 +02:00
|
|
|
dev = d3d->dev;
|
2018-05-03 15:20:06 +02:00
|
|
|
|
2016-10-20 05:07:03 +02:00
|
|
|
if (!overlay->vert_buf)
|
|
|
|
{
|
2018-03-03 15:28:58 +01:00
|
|
|
overlay->vert_buf = d3d9_vertex_buffer_new(
|
2018-05-03 15:20:06 +02:00
|
|
|
dev, sizeof(vert), D3DUSAGE_WRITEONLY,
|
2018-01-25 15:35:07 +01:00
|
|
|
#ifdef _XBOX
|
2019-06-24 23:40:50 +02:00
|
|
|
0,
|
2018-01-25 15:35:07 +01:00
|
|
|
#else
|
2018-01-25 14:34:20 +01:00
|
|
|
D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_TEX1,
|
2018-01-25 15:35:07 +01:00
|
|
|
#endif
|
2018-01-25 14:34:20 +01:00
|
|
|
D3DPOOL_MANAGED, NULL);
|
2016-10-20 05:07:03 +02:00
|
|
|
|
2019-06-24 23:40:50 +02:00
|
|
|
if (!overlay->vert_buf)
|
|
|
|
return;
|
2016-10-20 05:07:03 +02:00
|
|
|
}
|
|
|
|
|
2016-01-09 03:10:08 +01:00
|
|
|
for (i = 0; i < 4; i++)
|
|
|
|
{
|
2018-01-17 07:10:45 +01:00
|
|
|
vert[i].z = 0.5f;
|
|
|
|
vert[i].color = (((uint32_t)(overlay->alpha_mod * 0xFF)) << 24) | 0xFFFFFF;
|
2016-01-09 03:10:08 +01:00
|
|
|
}
|
2017-12-11 23:55:31 -08:00
|
|
|
|
2018-01-23 06:43:03 +01:00
|
|
|
d3d9_viewport_info(d3d, &vp);
|
2016-01-09 03:10:08 +01:00
|
|
|
|
2018-01-17 07:10:45 +01:00
|
|
|
vert[0].x = overlay->vert_coords[0];
|
|
|
|
vert[1].x = overlay->vert_coords[0] + overlay->vert_coords[2];
|
|
|
|
vert[2].x = overlay->vert_coords[0];
|
|
|
|
vert[3].x = overlay->vert_coords[0] + overlay->vert_coords[2];
|
|
|
|
vert[0].y = overlay->vert_coords[1];
|
|
|
|
vert[1].y = overlay->vert_coords[1];
|
|
|
|
vert[2].y = overlay->vert_coords[1] + overlay->vert_coords[3];
|
|
|
|
vert[3].y = overlay->vert_coords[1] + overlay->vert_coords[3];
|
|
|
|
|
|
|
|
vert[0].u = overlay->tex_coords[0];
|
|
|
|
vert[1].u = overlay->tex_coords[0] + overlay->tex_coords[2];
|
|
|
|
vert[2].u = overlay->tex_coords[0];
|
|
|
|
vert[3].u = overlay->tex_coords[0] + overlay->tex_coords[2];
|
|
|
|
vert[0].v = overlay->tex_coords[1];
|
|
|
|
vert[1].v = overlay->tex_coords[1];
|
|
|
|
vert[2].v = overlay->tex_coords[1] + overlay->tex_coords[3];
|
|
|
|
vert[3].v = overlay->tex_coords[1] + overlay->tex_coords[3];
|
2016-01-09 03:10:08 +01:00
|
|
|
|
2018-05-03 15:20:06 +02:00
|
|
|
verts = d3d9_vertex_buffer_lock((LPDIRECT3DVERTEXBUFFER9)overlay->vert_buf);
|
2016-01-09 03:10:08 +01:00
|
|
|
memcpy(verts, vert, sizeof(vert));
|
2018-05-03 15:20:06 +02:00
|
|
|
d3d9_vertex_buffer_unlock((LPDIRECT3DVERTEXBUFFER9)overlay->vert_buf);
|
2016-01-09 03:10:08 +01:00
|
|
|
|
2018-05-03 22:06:04 +02:00
|
|
|
d3d9_enable_blend_func(d3d->dev);
|
2018-01-23 02:55:33 +01:00
|
|
|
|
|
|
|
/* set vertex declaration for overlay. */
|
2018-05-03 15:20:06 +02:00
|
|
|
d3d9_vertex_declaration_new(dev, &vElems, (void**)&vertex_decl);
|
|
|
|
d3d9_set_vertex_declaration(dev, vertex_decl);
|
2018-03-03 15:28:58 +01:00
|
|
|
d3d9_vertex_declaration_free(vertex_decl);
|
2014-09-13 08:06:01 +02:00
|
|
|
|
2018-05-03 15:20:06 +02:00
|
|
|
d3d9_set_stream_source(dev, 0, (LPDIRECT3DVERTEXBUFFER9)overlay->vert_buf,
|
2016-01-09 03:10:08 +01:00
|
|
|
0, sizeof(*vert));
|
|
|
|
|
|
|
|
if (overlay->fullscreen)
|
|
|
|
{
|
2018-01-25 10:03:34 +01:00
|
|
|
D3DVIEWPORT9 vp_full;
|
2016-01-09 03:10:08 +01:00
|
|
|
|
|
|
|
vp_full.X = 0;
|
|
|
|
vp_full.Y = 0;
|
|
|
|
vp_full.Width = width;
|
|
|
|
vp_full.Height = height;
|
|
|
|
vp_full.MinZ = 0.0f;
|
|
|
|
vp_full.MaxZ = 1.0f;
|
2018-05-03 15:20:06 +02:00
|
|
|
d3d9_set_viewports(dev, &vp_full);
|
2016-01-09 03:10:08 +01:00
|
|
|
}
|
|
|
|
|
2018-04-24 14:47:21 +02:00
|
|
|
filter_type = D3DTEXF_LINEAR;
|
|
|
|
|
|
|
|
if (!force_linear)
|
|
|
|
{
|
2020-02-18 14:51:40 +01:00
|
|
|
settings_t *settings = config_get_ptr();
|
|
|
|
bool menu_linear_filter = settings->bools.menu_linear_filter;
|
|
|
|
if (!menu_linear_filter)
|
2018-04-24 14:47:21 +02:00
|
|
|
filter_type = D3DTEXF_POINT;
|
|
|
|
}
|
|
|
|
|
2016-01-09 03:10:08 +01:00
|
|
|
/* Render overlay. */
|
2018-05-03 15:20:06 +02:00
|
|
|
d3d9_set_texture(dev, 0, (LPDIRECT3DTEXTURE9)overlay->tex);
|
|
|
|
d3d9_set_sampler_address_u(dev, 0, D3DTADDRESS_BORDER);
|
|
|
|
d3d9_set_sampler_address_v(dev, 0, D3DTADDRESS_BORDER);
|
|
|
|
d3d9_set_sampler_minfilter(dev, 0, filter_type);
|
|
|
|
d3d9_set_sampler_magfilter(dev, 0, filter_type);
|
|
|
|
d3d9_draw_primitive(dev, D3DPT_TRIANGLESTRIP, 0, 2);
|
2016-01-09 03:10:08 +01:00
|
|
|
|
|
|
|
/* Restore previous state. */
|
2018-05-03 15:20:06 +02:00
|
|
|
d3d9_disable_blend_func(dev);
|
|
|
|
d3d9_set_viewports(dev, &d3d->final_viewport);
|
2016-01-09 03:10:08 +01:00
|
|
|
}
|
2019-07-11 01:10:00 +02:00
|
|
|
#endif
|
2016-01-09 03:10:08 +01:00
|
|
|
|
2018-05-03 22:03:12 +02:00
|
|
|
static void d3d9_free_overlay(d3d9_video_t *d3d, overlay_t *overlay)
|
2016-01-09 03:10:08 +01:00
|
|
|
{
|
|
|
|
if (!d3d)
|
|
|
|
return;
|
|
|
|
|
2018-05-03 15:20:06 +02:00
|
|
|
d3d9_texture_free((LPDIRECT3DTEXTURE9)overlay->tex);
|
2018-03-03 15:28:58 +01:00
|
|
|
d3d9_vertex_buffer_free(overlay->vert_buf, NULL);
|
2016-01-09 03:10:08 +01:00
|
|
|
}
|
|
|
|
|
2018-05-03 22:03:12 +02:00
|
|
|
static void d3d9_deinit_chain(d3d9_video_t *d3d)
|
2014-09-13 08:06:01 +02:00
|
|
|
{
|
2016-01-08 09:48:46 +01:00
|
|
|
if (!d3d || !d3d->renderchain_driver)
|
2016-01-07 00:29:12 +01:00
|
|
|
return;
|
|
|
|
|
|
|
|
if (d3d->renderchain_driver->chain_free)
|
|
|
|
d3d->renderchain_driver->chain_free(d3d->renderchain_data);
|
2015-04-06 17:47:29 +02:00
|
|
|
|
2015-04-06 17:18:28 +02:00
|
|
|
d3d->renderchain_driver = NULL;
|
|
|
|
d3d->renderchain_data = NULL;
|
2014-09-13 08:06:01 +02:00
|
|
|
}
|
|
|
|
|
2018-05-03 22:03:12 +02:00
|
|
|
static void d3d9_deinitialize(d3d9_video_t *d3d)
|
2014-09-13 08:06:01 +02:00
|
|
|
{
|
2015-03-15 17:51:27 +01:00
|
|
|
if (!d3d)
|
|
|
|
return;
|
2014-09-13 08:06:01 +02:00
|
|
|
|
2016-10-20 00:39:33 +02:00
|
|
|
font_driver_free_osd();
|
|
|
|
|
2018-03-03 15:28:58 +01:00
|
|
|
d3d9_deinit_chain(d3d);
|
|
|
|
d3d9_vertex_buffer_free(d3d->menu_display.buffer, d3d->menu_display.decl);
|
2018-05-14 06:33:26 +02:00
|
|
|
|
2018-01-14 02:21:48 +01:00
|
|
|
d3d->menu_display.buffer = NULL;
|
|
|
|
d3d->menu_display.decl = NULL;
|
2014-09-13 08:06:01 +02:00
|
|
|
}
|
|
|
|
|
2018-03-03 15:28:58 +01:00
|
|
|
static D3DFORMAT d3d9_get_color_format_backbuffer(bool rgb32, bool windowed)
|
2018-01-06 15:17:46 +01:00
|
|
|
{
|
2018-01-20 16:35:59 +01:00
|
|
|
D3DFORMAT fmt = D3DFMT_X8R8G8B8;
|
2018-01-06 15:17:46 +01:00
|
|
|
#ifdef _XBOX
|
2018-01-20 16:35:59 +01:00
|
|
|
if (!rgb32)
|
2018-03-03 15:28:58 +01:00
|
|
|
fmt = d3d9_get_rgb565_format();
|
2018-01-06 15:17:46 +01:00
|
|
|
#else
|
2018-01-06 16:10:05 +01:00
|
|
|
if (windowed)
|
|
|
|
{
|
|
|
|
D3DDISPLAYMODE display_mode;
|
2018-03-03 15:28:58 +01:00
|
|
|
if (d3d9_get_adapter_display_mode(g_pD3D9, 0, &display_mode))
|
2018-01-06 16:10:05 +01:00
|
|
|
fmt = display_mode.Format;
|
|
|
|
}
|
2018-01-06 15:17:46 +01:00
|
|
|
#endif
|
|
|
|
return fmt;
|
|
|
|
}
|
|
|
|
|
2018-01-23 02:55:33 +01:00
|
|
|
#ifdef _XBOX
|
2018-03-03 15:28:58 +01:00
|
|
|
static D3DFORMAT d3d9_get_color_format_front_buffer(void)
|
2018-01-06 15:25:11 +01:00
|
|
|
{
|
|
|
|
return D3DFMT_LE_X8R8G8B8;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2018-03-03 15:28:58 +01:00
|
|
|
static bool d3d9_is_windowed_enable(bool info_fullscreen)
|
2018-01-06 15:32:02 +01:00
|
|
|
{
|
|
|
|
#ifndef _XBOX
|
|
|
|
settings_t *settings = config_get_ptr();
|
2018-01-07 11:06:27 +01:00
|
|
|
if (!info_fullscreen)
|
|
|
|
return true;
|
2018-01-06 15:32:02 +01:00
|
|
|
if (settings)
|
2018-01-07 11:06:27 +01:00
|
|
|
return settings->bools.video_windowed_fullscreen;
|
2018-01-06 15:32:02 +01:00
|
|
|
#endif
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-03-02 15:30:39 +01:00
|
|
|
#ifdef _XBOX
|
2018-05-03 22:03:12 +02:00
|
|
|
static void d3d9_get_video_size(d3d9_video_t *d3d,
|
2018-03-02 15:30:39 +01:00
|
|
|
unsigned *width, unsigned *height)
|
|
|
|
{
|
|
|
|
XVIDEO_MODE video_mode;
|
|
|
|
|
|
|
|
XGetVideoMode(&video_mode);
|
|
|
|
|
|
|
|
*width = video_mode.dwDisplayWidth;
|
|
|
|
*height = video_mode.dwDisplayHeight;
|
|
|
|
|
|
|
|
d3d->resolution_hd_enable = false;
|
|
|
|
|
|
|
|
if(video_mode.fIsHiDef)
|
|
|
|
{
|
|
|
|
*width = 1280;
|
|
|
|
*height = 720;
|
|
|
|
d3d->resolution_hd_enable = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*width = 640;
|
|
|
|
*height = 480;
|
|
|
|
}
|
|
|
|
|
2020-03-07 17:04:06 +01:00
|
|
|
d3d->widescreen_mode = video_mode.fIsWideScreen;
|
2018-03-02 15:30:39 +01:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2018-03-03 15:28:58 +01:00
|
|
|
void d3d9_make_d3dpp(void *data,
|
2018-01-25 11:50:07 +01:00
|
|
|
const video_info_t *info, void *_d3dpp)
|
2015-04-11 21:54:52 +02:00
|
|
|
{
|
2018-05-03 22:03:12 +02:00
|
|
|
d3d9_video_t *d3d = (d3d9_video_t*)data;
|
2018-01-25 11:50:07 +01:00
|
|
|
D3DPRESENT_PARAMETERS *d3dpp = (D3DPRESENT_PARAMETERS*)_d3dpp;
|
2018-01-23 02:55:33 +01:00
|
|
|
#ifdef _XBOX
|
2015-11-11 04:49:20 +01:00
|
|
|
/* TODO/FIXME - get rid of global state dependencies. */
|
2018-01-07 11:06:27 +01:00
|
|
|
global_t *global = global_get_ptr();
|
2020-05-20 15:04:16 +02:00
|
|
|
int gamma_enable = global ?
|
|
|
|
global->console.screen.gamma_correction : 0;
|
2016-01-06 03:59:22 +01:00
|
|
|
#endif
|
2018-03-03 15:28:58 +01:00
|
|
|
bool windowed_enable = d3d9_is_windowed_enable(info->fullscreen);
|
2015-04-11 21:54:52 +02:00
|
|
|
|
|
|
|
memset(d3dpp, 0, sizeof(*d3dpp));
|
|
|
|
|
2018-01-07 11:06:27 +01:00
|
|
|
d3dpp->Windowed = windowed_enable;
|
|
|
|
FS_PRESENTINTERVAL(d3dpp) = D3DPRESENT_INTERVAL_IMMEDIATE;
|
2015-11-11 04:49:20 +01:00
|
|
|
|
|
|
|
if (info->vsync)
|
|
|
|
{
|
2020-02-18 14:51:40 +01:00
|
|
|
settings_t *settings = config_get_ptr();
|
|
|
|
unsigned video_swap_interval = settings->uints.video_swap_interval;
|
2018-01-07 11:06:27 +01:00
|
|
|
|
2020-02-18 14:51:40 +01:00
|
|
|
switch (video_swap_interval)
|
2015-11-11 04:49:20 +01:00
|
|
|
{
|
|
|
|
default:
|
|
|
|
case 1:
|
2017-09-05 00:57:58 +02:00
|
|
|
FS_PRESENTINTERVAL(d3dpp) = D3DPRESENT_INTERVAL_ONE;
|
2015-11-11 04:49:20 +01:00
|
|
|
break;
|
|
|
|
case 2:
|
2017-09-05 00:57:58 +02:00
|
|
|
FS_PRESENTINTERVAL(d3dpp) = D3DPRESENT_INTERVAL_TWO;
|
2015-11-11 04:49:20 +01:00
|
|
|
break;
|
|
|
|
case 3:
|
2017-09-05 00:57:58 +02:00
|
|
|
FS_PRESENTINTERVAL(d3dpp) = D3DPRESENT_INTERVAL_THREE;
|
2015-11-11 04:49:20 +01:00
|
|
|
break;
|
|
|
|
case 4:
|
2017-09-05 00:57:58 +02:00
|
|
|
FS_PRESENTINTERVAL(d3dpp) = D3DPRESENT_INTERVAL_FOUR;
|
2015-11-11 04:49:20 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-07 11:06:27 +01:00
|
|
|
d3dpp->SwapEffect = D3DSWAPEFFECT_DISCARD;
|
|
|
|
d3dpp->BackBufferCount = 2;
|
2018-03-03 15:28:58 +01:00
|
|
|
d3dpp->BackBufferFormat = d3d9_get_color_format_backbuffer(
|
2018-01-07 11:06:27 +01:00
|
|
|
info->rgb32, windowed_enable);
|
2018-01-06 15:17:46 +01:00
|
|
|
|
2018-01-23 02:55:33 +01:00
|
|
|
#ifdef _XBOX
|
2018-03-03 15:28:58 +01:00
|
|
|
d3dpp->FrontBufferFormat = d3d9_get_color_format_front_buffer();
|
2018-01-06 15:32:02 +01:00
|
|
|
|
2018-01-06 15:25:11 +01:00
|
|
|
if (gamma_enable)
|
2018-01-06 15:32:02 +01:00
|
|
|
{
|
2018-01-07 11:06:27 +01:00
|
|
|
d3dpp->BackBufferFormat = (D3DFORMAT)MAKESRGBFMT(
|
|
|
|
d3dpp->BackBufferFormat);
|
|
|
|
d3dpp->FrontBufferFormat = (D3DFORMAT)MAKESRGBFMT(
|
|
|
|
d3dpp->FrontBufferFormat);
|
2018-01-06 15:32:02 +01:00
|
|
|
}
|
2018-01-23 02:55:33 +01:00
|
|
|
#else
|
|
|
|
d3dpp->hDeviceWindow = win32_get_window();
|
2015-11-11 04:49:20 +01:00
|
|
|
#endif
|
|
|
|
|
2018-01-06 15:32:02 +01:00
|
|
|
if (!windowed_enable)
|
2015-11-11 04:49:20 +01:00
|
|
|
{
|
|
|
|
#ifdef _XBOX
|
2018-03-02 17:30:21 +01:00
|
|
|
unsigned width = 0;
|
|
|
|
unsigned height = 0;
|
2018-03-02 15:30:39 +01:00
|
|
|
d3d9_get_video_size(d3d, &width, &height);
|
2020-01-31 03:47:50 +01:00
|
|
|
video_driver_set_size(width, height);
|
2015-11-11 04:49:20 +01:00
|
|
|
#endif
|
2016-08-02 01:42:36 +02:00
|
|
|
video_driver_get_size(&d3dpp->BackBufferWidth,
|
|
|
|
&d3dpp->BackBufferHeight);
|
2015-11-11 04:49:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef _XBOX
|
|
|
|
d3dpp->MultiSampleType = D3DMULTISAMPLE_NONE;
|
|
|
|
d3dpp->EnableAutoDepthStencil = FALSE;
|
2020-03-07 17:04:06 +01:00
|
|
|
if (!d3d->widescreen_mode)
|
2015-11-11 04:49:20 +01:00
|
|
|
d3dpp->Flags |= D3DPRESENTFLAG_NO_LETTERBOX;
|
|
|
|
d3dpp->MultiSampleQuality = 0;
|
|
|
|
#endif
|
2015-04-11 21:54:52 +02:00
|
|
|
}
|
|
|
|
|
2018-01-23 06:43:03 +01:00
|
|
|
static bool d3d9_init_base(void *data, const video_info_t *info)
|
2014-09-13 08:06:01 +02:00
|
|
|
{
|
|
|
|
D3DPRESENT_PARAMETERS d3dpp;
|
2018-05-03 22:03:12 +02:00
|
|
|
HWND focus_window = NULL;
|
|
|
|
d3d9_video_t *d3d = (d3d9_video_t*)data;
|
2015-03-16 18:33:47 +01:00
|
|
|
|
2018-01-17 08:54:06 +01:00
|
|
|
#ifndef _XBOX
|
2018-05-03 22:03:12 +02:00
|
|
|
focus_window = win32_get_window();
|
2018-01-17 08:54:06 +01:00
|
|
|
#endif
|
|
|
|
|
2018-01-07 10:46:30 +01:00
|
|
|
memset(&d3dpp, 0, sizeof(d3dpp));
|
2014-09-13 08:06:01 +02:00
|
|
|
|
2018-03-03 15:28:58 +01:00
|
|
|
g_pD3D9 = (LPDIRECT3D9)d3d9_create();
|
2018-01-03 18:09:31 +01:00
|
|
|
|
2018-01-23 06:43:03 +01:00
|
|
|
/* this needs g_pD3D9 created first */
|
2018-03-03 15:28:58 +01:00
|
|
|
d3d9_make_d3dpp(d3d, info, &d3dpp);
|
2018-01-07 10:46:30 +01:00
|
|
|
|
2018-01-23 06:43:03 +01:00
|
|
|
if (!g_pD3D9)
|
2014-09-13 08:06:01 +02:00
|
|
|
{
|
2018-05-13 18:51:05 +02:00
|
|
|
RARCH_ERR("[D3D9]: Failed to create D3D interface.\n");
|
2014-09-13 08:06:01 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-03-03 15:28:58 +01:00
|
|
|
if (!d3d9_create_device(&d3d->dev, &d3dpp,
|
2018-01-23 06:43:03 +01:00
|
|
|
g_pD3D9,
|
2017-10-02 03:15:49 +02:00
|
|
|
focus_window,
|
|
|
|
d3d->cur_mon_id)
|
|
|
|
)
|
|
|
|
{
|
2018-05-13 18:51:05 +02:00
|
|
|
RARCH_ERR("[D3D9]: Failed to initialize device.\n");
|
2017-10-02 03:15:49 +02:00
|
|
|
return false;
|
2015-11-17 13:44:24 +01:00
|
|
|
}
|
2014-09-13 08:06:01 +02:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-03-03 15:28:58 +01:00
|
|
|
static void d3d9_calculate_rect(void *data,
|
2016-01-08 03:07:58 +01:00
|
|
|
unsigned *width, unsigned *height,
|
|
|
|
int *x, int *y,
|
2015-11-10 22:22:31 +01:00
|
|
|
bool force_full,
|
2015-11-10 22:18:08 +01:00
|
|
|
bool allow_rotate)
|
|
|
|
{
|
2018-05-03 22:03:12 +02:00
|
|
|
float device_aspect = (float)*width / *height;
|
|
|
|
d3d9_video_t *d3d = (d3d9_video_t*)data;
|
|
|
|
settings_t *settings = config_get_ptr();
|
2020-02-18 14:51:40 +01:00
|
|
|
bool scale_integer = settings->bools.video_scale_integer;
|
2015-11-10 22:22:31 +01:00
|
|
|
|
2016-01-08 03:07:58 +01:00
|
|
|
video_driver_get_size(width, height);
|
2016-02-13 22:07:56 +01:00
|
|
|
|
2018-03-02 16:38:57 +01:00
|
|
|
*x = 0;
|
|
|
|
*y = 0;
|
2016-01-08 03:14:49 +01:00
|
|
|
|
2020-02-18 14:51:40 +01:00
|
|
|
if (scale_integer && !force_full)
|
2015-11-10 22:22:31 +01:00
|
|
|
{
|
2017-04-15 19:43:52 +02:00
|
|
|
struct video_viewport vp;
|
|
|
|
|
|
|
|
vp.x = 0;
|
|
|
|
vp.y = 0;
|
|
|
|
vp.width = 0;
|
|
|
|
vp.height = 0;
|
|
|
|
vp.full_width = 0;
|
|
|
|
vp.full_height = 0;
|
|
|
|
|
2016-01-08 03:14:49 +01:00
|
|
|
video_viewport_get_scaled_integer(&vp,
|
|
|
|
*width,
|
|
|
|
*height,
|
2017-04-15 19:43:52 +02:00
|
|
|
video_driver_get_aspect_ratio(),
|
|
|
|
d3d->keep_aspect);
|
|
|
|
|
|
|
|
*x = vp.x;
|
|
|
|
*y = vp.y;
|
|
|
|
*width = vp.width;
|
|
|
|
*height = vp.height;
|
2015-11-10 22:22:31 +01:00
|
|
|
}
|
|
|
|
else if (d3d->keep_aspect && !force_full)
|
|
|
|
{
|
2016-01-08 03:14:49 +01:00
|
|
|
float desired_aspect = video_driver_get_aspect_ratio();
|
|
|
|
|
|
|
|
#if defined(HAVE_MENU)
|
2017-04-28 21:03:04 +02:00
|
|
|
if (settings->uints.video_aspect_ratio_idx == ASPECT_RATIO_CUSTOM)
|
2015-11-10 22:22:31 +01:00
|
|
|
{
|
|
|
|
video_viewport_t *custom = video_viewport_get_custom();
|
2015-11-10 22:18:08 +01:00
|
|
|
|
2017-04-29 16:22:07 +02:00
|
|
|
*x = custom->x;
|
|
|
|
*y = custom->y;
|
|
|
|
*width = custom->width;
|
|
|
|
*height = custom->height;
|
2015-11-10 22:22:31 +01:00
|
|
|
}
|
|
|
|
else
|
2016-01-08 03:14:49 +01:00
|
|
|
#endif
|
2015-11-10 22:22:31 +01:00
|
|
|
{
|
|
|
|
float delta;
|
|
|
|
|
2016-01-08 03:14:49 +01:00
|
|
|
if (fabsf(device_aspect - desired_aspect) < 0.0001f)
|
|
|
|
{
|
2017-12-11 23:55:31 -08:00
|
|
|
/* If the aspect ratios of screen and desired aspect
|
|
|
|
* ratio are sufficiently equal (floating point stuff),
|
2016-01-08 03:14:49 +01:00
|
|
|
* assume they are actually equal.
|
|
|
|
*/
|
|
|
|
}
|
2015-11-10 22:22:31 +01:00
|
|
|
else if (device_aspect > desired_aspect)
|
|
|
|
{
|
2017-10-02 07:48:57 +02:00
|
|
|
delta = (desired_aspect / device_aspect - 1.0f) / 2.0f + 0.5f;
|
|
|
|
*x = (int)(roundf(*width * (0.5f - delta)));
|
|
|
|
*width = (unsigned)(roundf(2.0f * (*width) * delta));
|
2015-11-10 22:22:31 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-10-02 07:48:57 +02:00
|
|
|
delta = (device_aspect / desired_aspect - 1.0f) / 2.0f + 0.5f;
|
|
|
|
*y = (int)(roundf(*height * (0.5f - delta)));
|
|
|
|
*height = (unsigned)(roundf(2.0f * (*height) * delta));
|
2015-11-10 22:22:31 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-01-08 03:07:58 +01:00
|
|
|
}
|
|
|
|
|
2018-05-14 16:57:34 +02:00
|
|
|
static void d3d9_set_font_rect(
|
|
|
|
d3d9_video_t *d3d,
|
|
|
|
const struct font_params *params)
|
|
|
|
{
|
|
|
|
settings_t *settings = config_get_ptr();
|
|
|
|
float pos_x = settings->floats.video_msg_pos_x;
|
|
|
|
float pos_y = settings->floats.video_msg_pos_y;
|
|
|
|
float font_size = settings->floats.video_font_size;
|
|
|
|
|
|
|
|
if (params)
|
|
|
|
{
|
|
|
|
pos_x = params->x;
|
|
|
|
pos_y = params->y;
|
|
|
|
font_size *= params->scale;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!d3d)
|
|
|
|
return;
|
|
|
|
|
|
|
|
d3d->font_rect.left = d3d->video_info.width * pos_x;
|
|
|
|
d3d->font_rect.right = d3d->video_info.width;
|
|
|
|
d3d->font_rect.top = (1.0f - pos_y) * d3d->video_info.height - font_size;
|
|
|
|
d3d->font_rect.bottom = d3d->video_info.height;
|
|
|
|
|
|
|
|
d3d->font_rect_shifted = d3d->font_rect;
|
|
|
|
d3d->font_rect_shifted.left -= 2;
|
|
|
|
d3d->font_rect_shifted.right -= 2;
|
|
|
|
d3d->font_rect_shifted.top += 2;
|
|
|
|
d3d->font_rect_shifted.bottom += 2;
|
|
|
|
}
|
|
|
|
|
2018-01-23 06:43:03 +01:00
|
|
|
static void d3d9_set_viewport(void *data,
|
2016-01-08 03:07:58 +01:00
|
|
|
unsigned width, unsigned height,
|
|
|
|
bool force_full,
|
|
|
|
bool allow_rotate)
|
|
|
|
{
|
|
|
|
int x = 0;
|
|
|
|
int y = 0;
|
2018-05-03 22:03:12 +02:00
|
|
|
d3d9_video_t *d3d = (d3d9_video_t*)data;
|
2015-11-10 22:22:31 +01:00
|
|
|
|
2018-03-03 15:28:58 +01:00
|
|
|
d3d9_calculate_rect(data, &width, &height, &x, &y,
|
2016-01-08 03:07:58 +01:00
|
|
|
force_full, allow_rotate);
|
2015-11-10 22:30:21 +01:00
|
|
|
|
|
|
|
/* D3D doesn't support negative X/Y viewports ... */
|
|
|
|
if (x < 0)
|
|
|
|
x = 0;
|
|
|
|
if (y < 0)
|
|
|
|
y = 0;
|
|
|
|
|
2018-05-13 18:24:19 +02:00
|
|
|
d3d->final_viewport.X = x;
|
|
|
|
d3d->final_viewport.Y = y;
|
|
|
|
d3d->final_viewport.Width = width;
|
|
|
|
d3d->final_viewport.Height = height;
|
|
|
|
d3d->final_viewport.MinZ = 0.0f;
|
|
|
|
d3d->final_viewport.MaxZ = 1.0f;
|
2015-11-10 22:30:21 +01:00
|
|
|
|
2018-05-14 16:57:34 +02:00
|
|
|
d3d9_set_font_rect(d3d, NULL);
|
2015-11-10 22:18:08 +01:00
|
|
|
}
|
|
|
|
|
2018-05-03 22:03:12 +02:00
|
|
|
static bool d3d9_initialize(d3d9_video_t *d3d, const video_info_t *info)
|
2014-09-13 08:06:01 +02:00
|
|
|
{
|
2015-05-20 02:30:31 +02:00
|
|
|
unsigned width, height;
|
2015-04-05 16:34:31 +02:00
|
|
|
bool ret = true;
|
2015-03-20 22:08:36 +01:00
|
|
|
settings_t *settings = config_get_ptr();
|
2015-01-17 06:30:39 +01:00
|
|
|
|
2015-03-15 17:51:27 +01:00
|
|
|
if (!d3d)
|
|
|
|
return false;
|
|
|
|
|
2018-01-23 06:43:03 +01:00
|
|
|
if (!g_pD3D9)
|
|
|
|
ret = d3d9_init_base(d3d, info);
|
2014-09-13 08:06:01 +02:00
|
|
|
else if (d3d->needs_restore)
|
|
|
|
{
|
|
|
|
D3DPRESENT_PARAMETERS d3dpp;
|
2015-03-16 18:33:47 +01:00
|
|
|
|
2018-03-03 15:28:58 +01:00
|
|
|
d3d9_make_d3dpp(d3d, info, &d3dpp);
|
2015-03-16 18:33:47 +01:00
|
|
|
|
2018-01-14 02:21:48 +01:00
|
|
|
/* the D3DX font driver uses POOL_DEFAULT resources
|
|
|
|
* and will prevent a clean reset here
|
|
|
|
* another approach would be to keep track of all created D3D
|
|
|
|
* font objects and free/realloc them around the d3d_reset call */
|
2018-08-14 11:40:42 +02:00
|
|
|
#ifdef HAVE_MENU
|
2018-01-14 02:21:48 +01:00
|
|
|
menu_driver_ctl(RARCH_MENU_CTL_DEINIT, NULL);
|
2018-08-14 11:40:42 +02:00
|
|
|
#endif
|
|
|
|
|
2018-03-03 15:28:58 +01:00
|
|
|
if (!d3d9_reset(d3d->dev, &d3dpp))
|
2014-09-13 08:06:01 +02:00
|
|
|
{
|
2018-03-03 15:28:58 +01:00
|
|
|
d3d9_deinitialize(d3d);
|
|
|
|
d3d9_device_free(NULL, g_pD3D9);
|
2018-01-23 06:43:03 +01:00
|
|
|
g_pD3D9 = NULL;
|
2015-11-14 20:02:55 +01:00
|
|
|
|
2018-01-23 06:43:03 +01:00
|
|
|
ret = d3d9_init_base(d3d, info);
|
2014-09-13 08:06:01 +02:00
|
|
|
if (ret)
|
2018-05-13 18:51:05 +02:00
|
|
|
RARCH_LOG("[D3D9]: Recovered from dead state.\n");
|
2014-09-13 08:06:01 +02:00
|
|
|
}
|
2018-08-14 11:40:42 +02:00
|
|
|
|
|
|
|
#ifdef HAVE_MENU
|
2018-01-14 02:21:48 +01:00
|
|
|
menu_driver_init(info->is_threaded);
|
2018-08-14 11:40:42 +02:00
|
|
|
#endif
|
2014-09-13 08:06:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!ret)
|
|
|
|
return ret;
|
|
|
|
|
2020-03-09 16:15:53 +01:00
|
|
|
if (!d3d9_init_chain(d3d, info->input_scale, info->rgb32))
|
2014-09-13 08:06:01 +02:00
|
|
|
{
|
2018-05-13 18:51:05 +02:00
|
|
|
RARCH_ERR("[D3D9]: Failed to initialize render chain.\n");
|
2014-09-13 08:06:01 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-11-10 22:22:31 +01:00
|
|
|
video_driver_get_size(&width, &height);
|
2018-01-23 06:43:03 +01:00
|
|
|
d3d9_set_viewport(d3d,
|
2019-06-24 23:40:50 +02:00
|
|
|
width, height, false, true);
|
2015-11-10 22:22:31 +01:00
|
|
|
|
2020-02-16 21:59:03 +01:00
|
|
|
font_driver_init_osd(d3d, info,
|
|
|
|
false,
|
2017-04-29 18:45:58 +02:00
|
|
|
info->is_threaded,
|
2018-03-03 15:28:58 +01:00
|
|
|
FONT_DRIVER_RENDER_D3D9_API);
|
2014-09-13 08:06:01 +02:00
|
|
|
|
2018-01-15 22:04:15 +01:00
|
|
|
{
|
2018-01-25 14:34:20 +01:00
|
|
|
static const D3DVERTEXELEMENT9 VertexElements[4] = {
|
2018-01-19 02:24:10 +01:00
|
|
|
{0, offsetof(Vertex, x), D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT,
|
|
|
|
D3DDECLUSAGE_POSITION, 0},
|
|
|
|
{0, offsetof(Vertex, u), D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT,
|
|
|
|
D3DDECLUSAGE_TEXCOORD, 0},
|
|
|
|
{0, offsetof(Vertex, color), D3DDECLTYPE_D3DCOLOR, D3DDECLMETHOD_DEFAULT,
|
|
|
|
D3DDECLUSAGE_COLOR, 0},
|
2018-01-15 22:04:15 +01:00
|
|
|
D3DDECL_END()
|
|
|
|
};
|
2018-05-03 22:06:04 +02:00
|
|
|
if (!d3d9_vertex_declaration_new(d3d->dev,
|
2018-01-15 22:04:15 +01:00
|
|
|
(void*)VertexElements, (void**)&d3d->menu_display.decl))
|
|
|
|
return false;
|
|
|
|
}
|
2018-01-14 02:21:48 +01:00
|
|
|
|
|
|
|
d3d->menu_display.offset = 0;
|
2018-01-15 20:58:13 +01:00
|
|
|
d3d->menu_display.size = 1024;
|
2018-03-03 15:28:58 +01:00
|
|
|
d3d->menu_display.buffer = d3d9_vertex_buffer_new(
|
2018-01-19 02:24:10 +01:00
|
|
|
d3d->dev, d3d->menu_display.size * sizeof(Vertex),
|
2018-01-25 14:34:20 +01:00
|
|
|
D3DUSAGE_WRITEONLY,
|
2018-01-25 15:35:07 +01:00
|
|
|
#ifdef _XBOX
|
|
|
|
0,
|
|
|
|
#else
|
2019-06-24 23:40:50 +02:00
|
|
|
D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_TEX1,
|
2018-01-25 15:35:07 +01:00
|
|
|
#endif
|
2018-01-25 14:34:20 +01:00
|
|
|
D3DPOOL_DEFAULT,
|
2018-01-14 02:21:48 +01:00
|
|
|
NULL);
|
|
|
|
|
|
|
|
if (!d3d->menu_display.buffer)
|
|
|
|
return false;
|
|
|
|
|
2018-01-15 03:45:37 +01:00
|
|
|
d3d_matrix_ortho_off_center_lh(&d3d->mvp_transposed, 0, 1, 0, 1, 0, 1);
|
|
|
|
d3d_matrix_transpose(&d3d->mvp, &d3d->mvp_transposed);
|
|
|
|
|
2018-05-03 22:06:04 +02:00
|
|
|
d3d9_set_render_state(d3d->dev, D3DRS_CULLMODE, D3DCULL_NONE);
|
2019-01-26 20:12:49 -05:00
|
|
|
d3d9_set_render_state(d3d->dev, D3DRS_SCISSORTESTENABLE, TRUE);
|
2018-01-15 03:45:37 +01:00
|
|
|
|
2014-09-13 08:06:01 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-01-23 06:43:03 +01:00
|
|
|
static bool d3d9_restore(void *data)
|
2016-01-07 01:00:11 +01:00
|
|
|
{
|
2018-05-03 22:03:12 +02:00
|
|
|
d3d9_video_t *d3d = (d3d9_video_t*)data;
|
2015-04-26 19:46:59 +02:00
|
|
|
|
2016-01-07 01:00:11 +01:00
|
|
|
if (!d3d)
|
|
|
|
return false;
|
2015-04-26 19:46:59 +02:00
|
|
|
|
2018-03-03 15:28:58 +01:00
|
|
|
d3d9_deinitialize(d3d);
|
2014-09-13 08:06:01 +02:00
|
|
|
|
2018-01-23 06:43:03 +01:00
|
|
|
if (!d3d9_initialize(d3d, &d3d->video_info))
|
2016-01-07 02:55:27 +01:00
|
|
|
{
|
2018-05-13 18:51:05 +02:00
|
|
|
RARCH_ERR("[D3D9]: Restore error.\n");
|
2016-01-07 02:55:27 +01:00
|
|
|
return false;
|
|
|
|
}
|
2014-09-13 08:06:01 +02:00
|
|
|
|
2016-01-07 02:55:27 +01:00
|
|
|
d3d->needs_restore = false;
|
|
|
|
|
|
|
|
return true;
|
2014-09-13 08:06:01 +02:00
|
|
|
}
|
|
|
|
|
2020-02-16 22:26:07 +01:00
|
|
|
static void d3d9_set_nonblock_state(void *data, bool state,
|
|
|
|
bool adaptive_vsync_enabled,
|
|
|
|
unsigned swap_interval)
|
2014-09-13 08:06:01 +02:00
|
|
|
{
|
2020-02-16 22:26:07 +01:00
|
|
|
#ifdef _XBOX
|
2018-09-12 00:07:43 +02:00
|
|
|
int interval = 0;
|
2020-02-16 22:26:07 +01:00
|
|
|
#endif
|
2018-05-03 22:03:12 +02:00
|
|
|
d3d9_video_t *d3d = (d3d9_video_t*)data;
|
2015-03-16 18:33:47 +01:00
|
|
|
|
|
|
|
if (!d3d)
|
|
|
|
return;
|
|
|
|
|
2020-02-16 22:26:07 +01:00
|
|
|
#ifdef _XBOX
|
2018-09-12 00:07:43 +02:00
|
|
|
if (!state)
|
|
|
|
interval = 1;
|
2020-02-16 22:26:07 +01:00
|
|
|
#endif
|
2018-09-12 00:07:43 +02:00
|
|
|
|
2014-09-13 08:06:01 +02:00
|
|
|
d3d->video_info.vsync = !state;
|
|
|
|
|
2018-03-02 15:30:39 +01:00
|
|
|
#ifdef _XBOX
|
2018-03-03 15:28:58 +01:00
|
|
|
d3d9_set_render_state(d3d->dev,
|
2018-03-02 17:03:34 +01:00
|
|
|
D3D9_PRESENTATIONINTERVAL,
|
2018-03-02 15:30:39 +01:00
|
|
|
interval ?
|
|
|
|
D3DPRESENT_INTERVAL_ONE : D3DPRESENT_INTERVAL_IMMEDIATE
|
|
|
|
);
|
|
|
|
#else
|
2016-01-08 08:16:26 +01:00
|
|
|
d3d->needs_restore = true;
|
2018-01-23 06:43:03 +01:00
|
|
|
d3d9_restore(d3d);
|
2016-01-07 00:38:42 +01:00
|
|
|
#endif
|
2014-09-13 08:06:01 +02:00
|
|
|
}
|
|
|
|
|
2018-01-23 06:43:03 +01:00
|
|
|
static bool d3d9_alive(void *data)
|
2014-09-13 08:06:01 +02:00
|
|
|
{
|
2018-05-03 22:03:12 +02:00
|
|
|
unsigned temp_width = 0;
|
|
|
|
unsigned temp_height = 0;
|
|
|
|
bool ret = false;
|
|
|
|
bool quit = false;
|
|
|
|
bool resize = false;
|
|
|
|
d3d9_video_t *d3d = (d3d9_video_t*)data;
|
2016-02-13 19:53:14 +01:00
|
|
|
|
2017-04-24 09:44:05 +02:00
|
|
|
/* Needed because some context drivers don't track their sizes */
|
|
|
|
video_driver_get_size(&temp_width, &temp_height);
|
|
|
|
|
2020-07-18 17:09:07 +02:00
|
|
|
win32_check_window(NULL, &quit, &resize, &temp_width, &temp_height);
|
2016-01-08 05:06:12 +01:00
|
|
|
|
2018-03-02 15:30:39 +01:00
|
|
|
if (quit)
|
|
|
|
d3d->quitting = quit;
|
2014-09-13 08:06:01 +02:00
|
|
|
|
2018-03-02 15:30:39 +01:00
|
|
|
if (resize)
|
|
|
|
{
|
|
|
|
d3d->should_resize = true;
|
2018-03-02 16:38:57 +01:00
|
|
|
d3d9_set_resize(d3d, temp_width, temp_height);
|
2018-03-02 15:30:39 +01:00
|
|
|
d3d9_restore(d3d);
|
2015-05-20 02:30:31 +02:00
|
|
|
}
|
2014-09-13 08:06:01 +02:00
|
|
|
|
2018-03-02 15:30:39 +01:00
|
|
|
ret = !quit;
|
|
|
|
|
2019-02-03 15:49:35 -08:00
|
|
|
if ( temp_width != 0 &&
|
2018-03-02 15:30:39 +01:00
|
|
|
temp_height != 0)
|
2020-01-31 03:47:50 +01:00
|
|
|
video_driver_set_size(temp_width, temp_height);
|
2015-05-20 02:30:31 +02:00
|
|
|
|
|
|
|
return ret;
|
2014-09-13 08:06:01 +02:00
|
|
|
}
|
|
|
|
|
2018-01-23 06:43:03 +01:00
|
|
|
static bool d3d9_suppress_screensaver(void *data, bool enable)
|
2015-01-18 22:43:07 +01:00
|
|
|
{
|
2018-03-02 15:30:39 +01:00
|
|
|
#ifdef _XBOX
|
|
|
|
return true;
|
|
|
|
#else
|
|
|
|
return win32_suppress_screensaver(data, enable);
|
|
|
|
#endif
|
2015-01-18 22:43:07 +01:00
|
|
|
}
|
|
|
|
|
2018-01-23 06:43:03 +01:00
|
|
|
static void d3d9_set_aspect_ratio(void *data, unsigned aspect_ratio_idx)
|
2014-09-13 08:06:01 +02:00
|
|
|
{
|
2018-05-03 22:03:12 +02:00
|
|
|
d3d9_video_t *d3d = (d3d9_video_t*)data;
|
2014-09-13 08:06:01 +02:00
|
|
|
|
2015-03-21 05:42:49 +01:00
|
|
|
if (!d3d)
|
|
|
|
return;
|
|
|
|
|
2015-11-10 05:30:25 +01:00
|
|
|
d3d->keep_aspect = true;
|
2015-03-21 05:42:49 +01:00
|
|
|
d3d->should_resize = true;
|
2014-09-13 08:06:01 +02:00
|
|
|
}
|
|
|
|
|
2018-01-23 06:43:03 +01:00
|
|
|
static void d3d9_apply_state_changes(void *data)
|
2014-09-13 08:06:01 +02:00
|
|
|
{
|
2018-05-03 22:03:12 +02:00
|
|
|
d3d9_video_t *d3d = (d3d9_video_t*)data;
|
2015-01-17 06:30:39 +01:00
|
|
|
if (d3d)
|
|
|
|
d3d->should_resize = true;
|
2014-09-13 08:06:01 +02:00
|
|
|
}
|
|
|
|
|
2018-01-23 06:43:03 +01:00
|
|
|
static void d3d9_set_osd_msg(void *data,
|
2017-04-23 22:20:11 +02:00
|
|
|
const char *msg,
|
2017-01-19 16:30:40 +01:00
|
|
|
const void *params, void *font)
|
2014-09-13 08:06:01 +02:00
|
|
|
{
|
2018-05-03 22:03:12 +02:00
|
|
|
d3d9_video_t *d3d = (d3d9_video_t*)data;
|
2018-05-03 22:06:04 +02:00
|
|
|
LPDIRECT3DDEVICE9 dev = d3d->dev;
|
2019-01-12 18:51:06 +01:00
|
|
|
const struct font_params *d3d_font_params = (const
|
|
|
|
struct font_params*)params;
|
2014-09-13 08:06:01 +02:00
|
|
|
|
2019-01-12 18:51:06 +01:00
|
|
|
d3d9_set_font_rect(d3d, d3d_font_params);
|
2018-05-03 15:20:06 +02:00
|
|
|
d3d9_begin_scene(dev);
|
2020-03-10 03:24:59 +01:00
|
|
|
font_driver_render_msg(d3d,
|
2020-01-04 16:24:14 +01:00
|
|
|
msg, d3d_font_params, font);
|
2018-05-03 15:20:06 +02:00
|
|
|
d3d9_end_scene(dev);
|
2014-09-13 08:06:01 +02:00
|
|
|
}
|
|
|
|
|
2018-05-03 22:03:12 +02:00
|
|
|
static bool d3d9_init_internal(d3d9_video_t *d3d,
|
2019-07-27 02:21:24 +02:00
|
|
|
const video_info_t *info, input_driver_t **input,
|
2014-09-13 08:06:01 +02:00
|
|
|
void **input_data)
|
|
|
|
{
|
2017-10-02 22:06:32 +02:00
|
|
|
#ifdef HAVE_MONITOR
|
|
|
|
bool windowed_full;
|
|
|
|
RECT mon_rect;
|
|
|
|
MONITORINFOEX current_mon;
|
|
|
|
HMONITOR hm_to_use;
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_WINDOW
|
|
|
|
DWORD style;
|
|
|
|
unsigned win_width = 0;
|
|
|
|
unsigned win_height = 0;
|
|
|
|
RECT rect = {0};
|
|
|
|
#endif
|
|
|
|
unsigned full_x = 0;
|
|
|
|
unsigned full_y = 0;
|
2017-04-23 09:38:26 +02:00
|
|
|
settings_t *settings = config_get_ptr();
|
2018-01-06 19:51:29 +01:00
|
|
|
overlay_t *menu = (overlay_t*)calloc(1, sizeof(*menu));
|
2015-01-17 06:30:39 +01:00
|
|
|
|
2018-01-06 19:51:29 +01:00
|
|
|
if (!menu)
|
2014-09-13 08:06:01 +02:00
|
|
|
return false;
|
|
|
|
|
2018-01-06 19:51:29 +01:00
|
|
|
d3d->menu = menu;
|
2018-01-06 15:42:47 +01:00
|
|
|
d3d->cur_mon_id = 0;
|
2015-11-11 03:48:05 +01:00
|
|
|
d3d->menu->tex_coords[0] = 0;
|
|
|
|
d3d->menu->tex_coords[1] = 0;
|
|
|
|
d3d->menu->tex_coords[2] = 1;
|
|
|
|
d3d->menu->tex_coords[3] = 1;
|
|
|
|
d3d->menu->vert_coords[0] = 0;
|
|
|
|
d3d->menu->vert_coords[1] = 1;
|
|
|
|
d3d->menu->vert_coords[2] = 1;
|
|
|
|
d3d->menu->vert_coords[3] = -1;
|
2014-09-13 08:06:01 +02:00
|
|
|
|
2016-01-09 05:37:03 +01:00
|
|
|
#ifdef HAVE_WINDOW
|
2018-05-14 03:57:27 +02:00
|
|
|
memset(&d3d->windowClass, 0, sizeof(d3d->windowClass));
|
2020-08-28 02:55:39 +02:00
|
|
|
d3d->windowClass.lpfnWndProc = wnd_proc_d3d_common;
|
2020-08-28 02:21:13 +02:00
|
|
|
#ifdef HAVE_DINPUT
|
|
|
|
if (string_is_equal(settings->arrays.input_driver, "dinput"))
|
|
|
|
d3d->windowClass.lpfnWndProc = wnd_proc_d3d_dinput;
|
2021-08-02 16:14:58 +02:00
|
|
|
#endif
|
|
|
|
#ifdef HAVE_WINRAWINPUT
|
|
|
|
if (string_is_equal(settings->arrays.input_driver, "raw"))
|
|
|
|
d3d->windowClass.lpfnWndProc = wnd_proc_d3d_winraw;
|
2020-08-28 02:21:13 +02:00
|
|
|
#endif
|
2015-11-19 08:30:37 +01:00
|
|
|
win32_window_init(&d3d->windowClass, true, NULL);
|
2015-11-19 08:37:25 +01:00
|
|
|
#endif
|
2014-09-13 08:06:01 +02:00
|
|
|
|
|
|
|
#ifdef HAVE_MONITOR
|
2015-11-11 17:57:15 +01:00
|
|
|
win32_monitor_info(¤t_mon, &hm_to_use, &d3d->cur_mon_id);
|
2018-01-06 19:51:29 +01:00
|
|
|
|
2018-05-12 19:03:39 +02:00
|
|
|
mon_rect = current_mon.rcMonitor;
|
|
|
|
g_win32_resize_width = info->width;
|
|
|
|
g_win32_resize_height = info->height;
|
2015-11-11 05:32:00 +01:00
|
|
|
|
2018-05-12 19:03:39 +02:00
|
|
|
windowed_full = settings->bools.video_windowed_fullscreen;
|
2014-09-13 08:06:01 +02:00
|
|
|
|
2018-05-12 19:03:39 +02:00
|
|
|
full_x = (windowed_full || info->width == 0) ?
|
2014-09-13 08:06:01 +02:00
|
|
|
(mon_rect.right - mon_rect.left) : info->width;
|
2018-05-12 19:03:39 +02:00
|
|
|
full_y = (windowed_full || info->height == 0) ?
|
2014-09-13 08:06:01 +02:00
|
|
|
(mon_rect.bottom - mon_rect.top) : info->height;
|
2018-01-06 19:51:29 +01:00
|
|
|
|
2018-05-13 18:51:05 +02:00
|
|
|
RARCH_LOG("[D3D9]: Monitor size: %dx%d.\n",
|
2014-09-13 08:06:01 +02:00
|
|
|
(int)(mon_rect.right - mon_rect.left),
|
|
|
|
(int)(mon_rect.bottom - mon_rect.top));
|
|
|
|
#else
|
2016-02-14 02:26:20 +01:00
|
|
|
{
|
2018-03-02 15:30:39 +01:00
|
|
|
d3d9_get_video_size(d3d, &full_x, &full_y);
|
2016-02-14 02:26:20 +01:00
|
|
|
}
|
2014-09-13 08:06:01 +02:00
|
|
|
#endif
|
2016-01-09 05:46:54 +01:00
|
|
|
{
|
|
|
|
unsigned new_width = info->fullscreen ? full_x : info->width;
|
|
|
|
unsigned new_height = info->fullscreen ? full_y : info->height;
|
2020-01-31 03:47:50 +01:00
|
|
|
video_driver_set_size(new_width, new_height);
|
2016-01-09 05:46:54 +01:00
|
|
|
}
|
2014-09-13 08:06:01 +02:00
|
|
|
|
2015-04-06 01:43:47 +02:00
|
|
|
#ifdef HAVE_WINDOW
|
2015-11-12 05:39:55 +01:00
|
|
|
video_driver_get_size(&win_width, &win_height);
|
2015-11-12 02:35:05 +01:00
|
|
|
|
2016-08-02 01:42:36 +02:00
|
|
|
win32_set_style(¤t_mon, &hm_to_use, &win_width, &win_height,
|
|
|
|
info->fullscreen, windowed_full, &rect, &mon_rect, &style);
|
2014-09-13 08:06:01 +02:00
|
|
|
|
2015-11-12 02:51:40 +01:00
|
|
|
win32_window_create(d3d, style, &mon_rect, win_width,
|
|
|
|
win_height, info->fullscreen);
|
2014-09-13 08:06:01 +02:00
|
|
|
|
2016-01-09 05:04:47 +01:00
|
|
|
win32_set_window(&win_width, &win_height, info->fullscreen,
|
2019-06-24 23:40:50 +02:00
|
|
|
windowed_full, &rect);
|
2014-09-13 08:06:01 +02:00
|
|
|
#endif
|
|
|
|
|
2019-06-25 10:54:31 +02:00
|
|
|
d3d->video_info = *info;
|
|
|
|
|
|
|
|
if (!d3d9_initialize(d3d, &d3d->video_info))
|
|
|
|
return false;
|
|
|
|
|
2020-03-07 17:04:06 +01:00
|
|
|
d3d9_fake_context.get_flags = d3d9_get_flags;
|
2020-01-03 09:33:20 +08:00
|
|
|
#ifndef _XBOX_
|
2020-03-07 17:04:06 +01:00
|
|
|
d3d9_fake_context.get_metrics = win32_get_metrics;
|
2020-01-03 09:33:20 +08:00
|
|
|
#endif
|
2020-03-07 17:04:06 +01:00
|
|
|
video_context_driver_set(&d3d9_fake_context);
|
2019-07-21 12:13:04 +02:00
|
|
|
#if defined(HAVE_CG) || defined(HAVE_HLSL)
|
2020-03-07 17:04:06 +01:00
|
|
|
{
|
|
|
|
const char *shader_preset = retroarch_get_shader_preset();
|
|
|
|
enum rarch_shader_type type = video_shader_parse_type(shader_preset);
|
2014-09-13 08:06:01 +02:00
|
|
|
|
2020-03-07 17:04:06 +01:00
|
|
|
d3d9_set_shader(d3d, type, shader_preset);
|
2019-06-24 23:40:50 +02:00
|
|
|
}
|
2020-03-07 17:04:06 +01:00
|
|
|
#endif
|
2014-09-13 08:06:01 +02:00
|
|
|
|
2018-12-29 02:20:25 +01:00
|
|
|
d3d_input_driver(settings->arrays.input_joypad_driver,
|
|
|
|
settings->arrays.input_joypad_driver, input, input_data);
|
2014-09-13 08:06:01 +02:00
|
|
|
|
2019-03-07 19:17:54 -05:00
|
|
|
{
|
2019-03-11 17:07:49 +01:00
|
|
|
char version_str[128];
|
2019-03-07 19:17:54 -05:00
|
|
|
D3DADAPTER_IDENTIFIER9 ident = {0};
|
2019-03-11 17:07:49 +01:00
|
|
|
|
2019-03-07 19:17:54 -05:00
|
|
|
IDirect3D9_GetAdapterIdentifier(g_pD3D9, 0, 0, &ident);
|
|
|
|
|
|
|
|
version_str[0] = '\0';
|
|
|
|
|
|
|
|
snprintf(version_str, sizeof(version_str), "%u.%u.%u.%u", HIWORD(ident.DriverVersion.HighPart), LOWORD(ident.DriverVersion.HighPart), HIWORD(ident.DriverVersion.LowPart), LOWORD(ident.DriverVersion.LowPart));
|
|
|
|
|
|
|
|
RARCH_LOG("[D3D9]: Using GPU: %s\n", ident.Description);
|
|
|
|
RARCH_LOG("[D3D9]: GPU API Version: %s\n", version_str);
|
|
|
|
|
|
|
|
video_driver_set_gpu_device_string(ident.Description);
|
|
|
|
video_driver_set_gpu_api_version_string(version_str);
|
|
|
|
}
|
|
|
|
|
2018-05-13 18:51:05 +02:00
|
|
|
RARCH_LOG("[D3D9]: Init complete.\n");
|
2014-09-13 08:06:01 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-01-23 06:43:03 +01:00
|
|
|
static void d3d9_set_rotation(void *data, unsigned rot)
|
2014-09-13 08:06:01 +02:00
|
|
|
{
|
2018-05-03 22:03:12 +02:00
|
|
|
d3d9_video_t *d3d = (d3d9_video_t*)data;
|
2018-01-22 23:03:02 +01:00
|
|
|
struct video_ortho ortho = {0, 1, 0, 1, -1, 1};
|
2015-11-10 00:13:17 +01:00
|
|
|
|
|
|
|
if (!d3d)
|
|
|
|
return;
|
|
|
|
|
2018-01-22 23:03:02 +01:00
|
|
|
d3d->dev_rotation = rot;
|
2014-09-13 08:06:01 +02:00
|
|
|
}
|
|
|
|
|
2018-01-23 06:43:03 +01:00
|
|
|
static void *d3d9_init(const video_info_t *info,
|
2019-07-27 02:21:24 +02:00
|
|
|
input_driver_t **input, void **input_data)
|
2014-09-13 08:06:01 +02:00
|
|
|
{
|
2018-05-03 22:03:12 +02:00
|
|
|
d3d9_video_t *d3d = (d3d9_video_t*)calloc(1, sizeof(*d3d));
|
2015-01-17 06:30:39 +01:00
|
|
|
|
2018-03-02 17:00:11 +01:00
|
|
|
if (!d3d)
|
2018-01-03 18:38:13 +01:00
|
|
|
return NULL;
|
|
|
|
|
2018-03-03 15:28:58 +01:00
|
|
|
if (!d3d9_initialize_symbols(GFX_CTX_DIRECT3D9_API))
|
2018-03-02 17:00:11 +01:00
|
|
|
{
|
|
|
|
free(d3d);
|
|
|
|
return NULL;
|
|
|
|
}
|
2014-09-13 08:06:01 +02:00
|
|
|
|
2018-03-02 17:00:11 +01:00
|
|
|
#ifndef _XBOX
|
|
|
|
win32_window_reset();
|
|
|
|
win32_monitor_init();
|
|
|
|
#endif
|
2014-09-13 08:06:01 +02:00
|
|
|
|
|
|
|
/* Default values */
|
2016-01-07 06:50:32 +01:00
|
|
|
d3d->dev = NULL;
|
|
|
|
d3d->dev_rotation = 0;
|
|
|
|
d3d->needs_restore = false;
|
2014-09-13 08:06:01 +02:00
|
|
|
#ifdef HAVE_OVERLAY
|
2016-01-07 06:50:32 +01:00
|
|
|
d3d->overlays_enabled = false;
|
2014-09-13 08:06:01 +02:00
|
|
|
#endif
|
2016-01-07 06:50:32 +01:00
|
|
|
d3d->should_resize = false;
|
2017-12-31 17:53:11 +01:00
|
|
|
d3d->menu = NULL;
|
2014-09-13 08:06:01 +02:00
|
|
|
|
2018-01-23 06:43:03 +01:00
|
|
|
if (!d3d9_init_internal(d3d, info, input, input_data))
|
2014-09-13 08:06:01 +02:00
|
|
|
{
|
2018-05-13 18:51:05 +02:00
|
|
|
RARCH_ERR("[D3D9]: Failed to init D3D.\n");
|
2018-03-02 17:23:43 +01:00
|
|
|
free(d3d);
|
|
|
|
return NULL;
|
2014-09-13 08:06:01 +02:00
|
|
|
}
|
|
|
|
|
2016-01-07 06:50:32 +01:00
|
|
|
d3d->keep_aspect = info->force_aspect;
|
2014-09-13 08:06:01 +02:00
|
|
|
|
2016-01-07 06:50:32 +01:00
|
|
|
return d3d;
|
2014-09-13 08:06:01 +02:00
|
|
|
}
|
|
|
|
|
2016-01-09 03:10:37 +01:00
|
|
|
#ifdef HAVE_OVERLAY
|
2018-05-03 22:03:12 +02:00
|
|
|
static void d3d9_free_overlays(d3d9_video_t *d3d)
|
2016-01-09 03:10:37 +01:00
|
|
|
{
|
|
|
|
unsigned i;
|
|
|
|
|
|
|
|
if (!d3d)
|
|
|
|
return;
|
|
|
|
|
2017-10-02 06:12:33 +02:00
|
|
|
for (i = 0; i < d3d->overlays_size; i++)
|
2018-01-23 06:43:03 +01:00
|
|
|
d3d9_free_overlay(d3d, &d3d->overlays[i]);
|
2017-10-02 06:12:33 +02:00
|
|
|
free(d3d->overlays);
|
|
|
|
d3d->overlays = NULL;
|
|
|
|
d3d->overlays_size = 0;
|
2016-01-09 03:10:37 +01:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2018-01-23 06:43:03 +01:00
|
|
|
static void d3d9_free(void *data)
|
2014-09-13 08:06:01 +02:00
|
|
|
{
|
2018-05-03 22:03:12 +02:00
|
|
|
d3d9_video_t *d3d = (d3d9_video_t*)data;
|
2014-09-15 08:17:16 -04:00
|
|
|
|
|
|
|
if (!d3d)
|
|
|
|
return;
|
|
|
|
|
2014-09-13 08:06:01 +02:00
|
|
|
#ifdef HAVE_OVERLAY
|
2018-01-23 06:43:03 +01:00
|
|
|
d3d9_free_overlays(d3d);
|
2017-10-02 06:12:33 +02:00
|
|
|
if (d3d->overlays)
|
|
|
|
free(d3d->overlays);
|
|
|
|
d3d->overlays = NULL;
|
|
|
|
d3d->overlays_size = 0;
|
2014-09-13 08:06:01 +02:00
|
|
|
#endif
|
2015-04-06 01:43:47 +02:00
|
|
|
|
2018-01-23 06:43:03 +01:00
|
|
|
d3d9_free_overlay(d3d, d3d->menu);
|
2016-01-07 04:59:39 +01:00
|
|
|
if (d3d->menu)
|
2017-04-23 09:38:26 +02:00
|
|
|
free(d3d->menu);
|
2017-10-02 06:12:33 +02:00
|
|
|
d3d->menu = NULL;
|
2016-01-07 00:03:05 +01:00
|
|
|
|
2018-03-03 15:28:58 +01:00
|
|
|
d3d9_deinitialize(d3d);
|
2017-10-02 06:12:33 +02:00
|
|
|
|
2017-10-02 01:38:06 +02:00
|
|
|
if (!string_is_empty(d3d->shader_path))
|
|
|
|
free(d3d->shader_path);
|
|
|
|
|
|
|
|
d3d->shader_path = NULL;
|
2018-03-03 15:28:58 +01:00
|
|
|
d3d9_device_free(d3d->dev, g_pD3D9);
|
2017-10-02 01:38:06 +02:00
|
|
|
d3d->dev = NULL;
|
2018-01-23 06:43:03 +01:00
|
|
|
g_pD3D9 = NULL;
|
2014-09-13 08:06:01 +02:00
|
|
|
|
2018-03-03 15:28:58 +01:00
|
|
|
d3d9_deinitialize_symbols();
|
2018-01-03 18:38:13 +01:00
|
|
|
|
2017-09-14 22:24:04 +02:00
|
|
|
#ifndef _XBOX
|
2018-03-02 17:00:11 +01:00
|
|
|
win32_monitor_from_window();
|
2015-11-17 09:44:26 +01:00
|
|
|
win32_destroy_window();
|
2017-09-14 22:24:04 +02:00
|
|
|
#endif
|
2018-03-02 17:00:11 +01:00
|
|
|
free(d3d);
|
2014-09-13 08:06:01 +02:00
|
|
|
}
|
|
|
|
|
2015-11-17 11:42:59 +01:00
|
|
|
#ifdef HAVE_OVERLAY
|
2018-01-23 06:43:03 +01:00
|
|
|
static void d3d9_overlay_tex_geom(
|
2015-11-10 05:11:49 +01:00
|
|
|
void *data,
|
2014-09-13 08:06:01 +02:00
|
|
|
unsigned index,
|
|
|
|
float x, float y,
|
|
|
|
float w, float h)
|
|
|
|
{
|
2018-05-03 22:03:12 +02:00
|
|
|
d3d9_video_t *d3d = (d3d9_video_t*)data;
|
|
|
|
|
2015-03-16 18:33:47 +01:00
|
|
|
if (!d3d)
|
|
|
|
return;
|
|
|
|
|
2015-11-11 03:48:05 +01:00
|
|
|
d3d->overlays[index].tex_coords[0] = x;
|
|
|
|
d3d->overlays[index].tex_coords[1] = y;
|
|
|
|
d3d->overlays[index].tex_coords[2] = w;
|
|
|
|
d3d->overlays[index].tex_coords[3] = h;
|
2014-09-13 08:06:01 +02:00
|
|
|
}
|
|
|
|
|
2018-01-23 06:43:03 +01:00
|
|
|
static void d3d9_overlay_vertex_geom(
|
2015-11-10 05:11:49 +01:00
|
|
|
void *data,
|
2014-09-13 08:06:01 +02:00
|
|
|
unsigned index,
|
|
|
|
float x, float y,
|
|
|
|
float w, float h)
|
|
|
|
{
|
2018-05-03 22:03:12 +02:00
|
|
|
d3d9_video_t *d3d = (d3d9_video_t*)data;
|
|
|
|
|
2015-03-16 18:33:47 +01:00
|
|
|
if (!d3d)
|
|
|
|
return;
|
|
|
|
|
2015-11-11 03:48:05 +01:00
|
|
|
y = 1.0f - y;
|
|
|
|
h = -h;
|
|
|
|
d3d->overlays[index].vert_coords[0] = x;
|
|
|
|
d3d->overlays[index].vert_coords[1] = y;
|
|
|
|
d3d->overlays[index].vert_coords[2] = w;
|
|
|
|
d3d->overlays[index].vert_coords[3] = h;
|
2014-09-13 08:06:01 +02:00
|
|
|
}
|
|
|
|
|
2018-01-23 06:43:03 +01:00
|
|
|
static bool d3d9_overlay_load(void *data,
|
2015-07-11 08:14:39 +02:00
|
|
|
const void *image_data, unsigned num_images)
|
2014-09-13 08:06:01 +02:00
|
|
|
{
|
|
|
|
unsigned i, y;
|
2017-10-02 06:12:33 +02:00
|
|
|
overlay_t *new_overlays = NULL;
|
2018-05-03 22:03:12 +02:00
|
|
|
d3d9_video_t *d3d = (d3d9_video_t*)data;
|
2015-07-11 19:47:20 +02:00
|
|
|
const struct texture_image *images = (const struct texture_image*)
|
2015-07-11 08:14:39 +02:00
|
|
|
image_data;
|
2015-01-17 06:30:39 +01:00
|
|
|
|
2015-03-15 17:54:53 +01:00
|
|
|
if (!d3d)
|
2019-06-24 23:40:50 +02:00
|
|
|
return false;
|
2015-03-15 17:54:53 +01:00
|
|
|
|
2018-01-23 06:43:03 +01:00
|
|
|
d3d9_free_overlays(d3d);
|
2017-10-02 06:12:33 +02:00
|
|
|
d3d->overlays = (overlay_t*)calloc(num_images, sizeof(*d3d->overlays));
|
|
|
|
d3d->overlays_size = num_images;
|
2014-09-13 08:06:01 +02:00
|
|
|
|
|
|
|
for (i = 0; i < num_images; i++)
|
|
|
|
{
|
2015-01-17 06:30:39 +01:00
|
|
|
D3DLOCKED_RECT d3dlr;
|
2015-04-05 16:34:31 +02:00
|
|
|
unsigned width = images[i].width;
|
|
|
|
unsigned height = images[i].height;
|
2014-09-13 22:25:30 +02:00
|
|
|
overlay_t *overlay = (overlay_t*)&d3d->overlays[i];
|
2014-09-13 08:06:01 +02:00
|
|
|
|
2018-03-03 15:28:58 +01:00
|
|
|
overlay->tex = d3d9_texture_new(d3d->dev, NULL,
|
2014-09-13 18:42:13 +02:00
|
|
|
width, height, 1,
|
2014-09-13 08:06:01 +02:00
|
|
|
0,
|
2018-03-03 15:28:58 +01:00
|
|
|
d3d9_get_argb8888_format(),
|
2015-05-20 17:28:12 -05:00
|
|
|
D3DPOOL_MANAGED, 0, 0, 0,
|
2018-01-16 09:11:14 +01:00
|
|
|
NULL, NULL, false);
|
2014-09-13 18:42:13 +02:00
|
|
|
|
2014-09-13 22:25:30 +02:00
|
|
|
if (!overlay->tex)
|
2014-09-13 08:06:01 +02:00
|
|
|
{
|
2018-05-13 18:51:05 +02:00
|
|
|
RARCH_ERR("[D3D9]: Failed to create overlay texture\n");
|
2014-09-13 08:06:01 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-05-03 15:20:06 +02:00
|
|
|
if (d3d9_lock_rectangle((LPDIRECT3DTEXTURE9)overlay->tex, 0, &d3dlr,
|
2015-11-09 15:39:47 +01:00
|
|
|
NULL, 0, D3DLOCK_NOSYSLOCK))
|
2014-09-13 08:06:01 +02:00
|
|
|
{
|
2015-01-17 06:30:39 +01:00
|
|
|
uint32_t *dst = (uint32_t*)(d3dlr.pBits);
|
2014-09-13 08:06:01 +02:00
|
|
|
const uint32_t *src = images[i].pixels;
|
2015-01-17 06:30:39 +01:00
|
|
|
unsigned pitch = d3dlr.Pitch >> 2;
|
|
|
|
|
2014-09-13 08:06:01 +02:00
|
|
|
for (y = 0; y < height; y++, dst += pitch, src += width)
|
|
|
|
memcpy(dst, src, width << 2);
|
2018-05-03 15:20:06 +02:00
|
|
|
d3d9_unlock_rectangle((LPDIRECT3DTEXTURE9)overlay->tex);
|
2014-09-13 08:06:01 +02:00
|
|
|
}
|
|
|
|
|
2015-04-05 16:34:31 +02:00
|
|
|
overlay->tex_w = width;
|
|
|
|
overlay->tex_h = height;
|
2014-09-13 08:06:01 +02:00
|
|
|
|
|
|
|
/* Default. Stretch to whole screen. */
|
2018-01-23 06:43:03 +01:00
|
|
|
d3d9_overlay_tex_geom(d3d, i, 0, 0, 1, 1);
|
|
|
|
d3d9_overlay_vertex_geom(d3d, i, 0, 0, 1, 1);
|
2014-09-13 08:06:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-01-23 06:43:03 +01:00
|
|
|
static void d3d9_overlay_enable(void *data, bool state)
|
2014-09-13 08:06:01 +02:00
|
|
|
{
|
|
|
|
unsigned i;
|
2018-05-03 22:03:12 +02:00
|
|
|
d3d9_video_t *d3d = (d3d9_video_t*)data;
|
2014-09-13 08:06:01 +02:00
|
|
|
|
2014-11-14 23:06:34 -05:00
|
|
|
if (!d3d)
|
|
|
|
return;
|
|
|
|
|
2017-10-02 06:12:33 +02:00
|
|
|
for (i = 0; i < d3d->overlays_size; i++)
|
2014-09-13 08:06:01 +02:00
|
|
|
d3d->overlays_enabled = state;
|
|
|
|
|
2020-01-04 15:40:02 +01:00
|
|
|
#ifndef XBOX
|
|
|
|
win32_show_cursor(d3d, state);
|
|
|
|
#endif
|
2014-09-13 08:06:01 +02:00
|
|
|
}
|
|
|
|
|
2018-01-23 06:43:03 +01:00
|
|
|
static void d3d9_overlay_full_screen(void *data, bool enable)
|
2014-09-13 08:06:01 +02:00
|
|
|
{
|
|
|
|
unsigned i;
|
2018-05-03 22:03:12 +02:00
|
|
|
d3d9_video_t *d3d = (d3d9_video_t*)data;
|
2014-09-13 08:06:01 +02:00
|
|
|
|
2017-10-02 06:12:33 +02:00
|
|
|
for (i = 0; i < d3d->overlays_size; i++)
|
2014-09-13 08:06:01 +02:00
|
|
|
d3d->overlays[i].fullscreen = enable;
|
|
|
|
}
|
|
|
|
|
2018-01-23 06:43:03 +01:00
|
|
|
static void d3d9_overlay_set_alpha(void *data, unsigned index, float mod)
|
2014-09-13 08:06:01 +02:00
|
|
|
{
|
2018-05-03 22:03:12 +02:00
|
|
|
d3d9_video_t *d3d = (d3d9_video_t*)data;
|
2015-01-17 06:30:39 +01:00
|
|
|
if (d3d)
|
|
|
|
d3d->overlays[index].alpha_mod = mod;
|
2014-09-13 08:06:01 +02:00
|
|
|
}
|
|
|
|
|
2018-01-23 06:43:03 +01:00
|
|
|
static const video_overlay_interface_t d3d9_overlay_interface = {
|
|
|
|
d3d9_overlay_enable,
|
|
|
|
d3d9_overlay_load,
|
|
|
|
d3d9_overlay_tex_geom,
|
|
|
|
d3d9_overlay_vertex_geom,
|
|
|
|
d3d9_overlay_full_screen,
|
|
|
|
d3d9_overlay_set_alpha,
|
2014-09-13 08:06:01 +02:00
|
|
|
};
|
|
|
|
|
2018-01-23 06:43:03 +01:00
|
|
|
static void d3d9_get_overlay_interface(void *data,
|
2014-09-13 08:06:01 +02:00
|
|
|
const video_overlay_interface_t **iface)
|
|
|
|
{
|
|
|
|
(void)data;
|
2018-01-23 06:43:03 +01:00
|
|
|
*iface = &d3d9_overlay_interface;
|
2014-09-13 08:06:01 +02:00
|
|
|
}
|
2014-01-09 18:44:25 +01:00
|
|
|
#endif
|
|
|
|
|
2018-01-23 06:43:03 +01:00
|
|
|
static bool d3d9_frame(void *data, const void *frame,
|
2015-05-20 01:54:57 +02:00
|
|
|
unsigned frame_width, unsigned frame_height,
|
2015-08-03 23:01:07 +02:00
|
|
|
uint64_t frame_count, unsigned pitch,
|
2017-01-18 17:41:27 +01:00
|
|
|
const char *msg, video_frame_info_t *video_info)
|
2012-10-26 21:09:30 +02:00
|
|
|
{
|
2018-01-25 10:03:34 +01:00
|
|
|
D3DVIEWPORT9 screen_vp;
|
2015-09-20 10:02:47 +02:00
|
|
|
unsigned i = 0;
|
2018-05-03 22:03:12 +02:00
|
|
|
d3d9_video_t *d3d = (d3d9_video_t*)data;
|
2017-01-18 23:07:05 +01:00
|
|
|
unsigned width = video_info->width;
|
|
|
|
unsigned height = video_info->height;
|
2020-03-09 16:15:53 +01:00
|
|
|
bool statistics_show = video_info->statistics_show;
|
2020-09-18 11:57:32 -04:00
|
|
|
unsigned black_frame_insertion = video_info->black_frame_insertion;
|
2020-03-09 16:15:53 +01:00
|
|
|
struct font_params *osd_params = (struct font_params*)
|
|
|
|
&video_info->osd_stat_params;
|
|
|
|
const char *stat_text = video_info->stat_text;
|
2020-05-19 16:20:43 +02:00
|
|
|
bool menu_is_alive = video_info->menu_is_alive;
|
2020-08-03 16:33:54 +02:00
|
|
|
#ifdef HAVE_GFX_WIDGETS
|
|
|
|
bool widgets_active = video_info->widgets_active;
|
|
|
|
#endif
|
2015-01-17 06:47:00 +01:00
|
|
|
|
2015-05-20 01:54:57 +02:00
|
|
|
if (!frame)
|
2014-01-09 18:44:25 +01:00
|
|
|
return true;
|
|
|
|
|
2014-09-08 19:28:10 +02:00
|
|
|
/* We cannot recover in fullscreen. */
|
2016-01-07 00:26:38 +01:00
|
|
|
if (d3d->needs_restore)
|
2014-01-09 18:44:25 +01:00
|
|
|
{
|
2018-01-17 08:51:56 +01:00
|
|
|
#ifndef _XBOX
|
|
|
|
HWND window = win32_get_window();
|
2016-01-07 00:26:38 +01:00
|
|
|
if (IsIconic(window))
|
|
|
|
return true;
|
2018-01-17 08:51:56 +01:00
|
|
|
#endif
|
2016-01-07 00:26:38 +01:00
|
|
|
|
2018-01-23 06:43:03 +01:00
|
|
|
if (!d3d9_restore(d3d))
|
2016-01-07 00:26:38 +01:00
|
|
|
{
|
2018-05-13 18:51:05 +02:00
|
|
|
RARCH_ERR("[D3D9]: Failed to restore.\n");
|
2016-01-07 00:26:38 +01:00
|
|
|
return false;
|
|
|
|
}
|
2014-01-09 18:44:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (d3d->should_resize)
|
|
|
|
{
|
2018-01-23 06:43:03 +01:00
|
|
|
d3d9_set_viewport(d3d, width, height, false, true);
|
2015-11-11 01:34:00 +01:00
|
|
|
if (d3d->renderchain_driver->set_final_viewport)
|
|
|
|
d3d->renderchain_driver->set_final_viewport(d3d,
|
|
|
|
d3d->renderchain_data, &d3d->final_viewport);
|
|
|
|
|
|
|
|
d3d->should_resize = false;
|
2014-01-09 18:44:25 +01:00
|
|
|
}
|
|
|
|
|
2015-05-20 17:28:12 -05:00
|
|
|
/* render_chain() only clears out viewport,
|
2014-09-11 20:31:37 +02:00
|
|
|
* clear out everything. */
|
2017-01-18 17:41:27 +01:00
|
|
|
screen_vp.X = 0;
|
|
|
|
screen_vp.Y = 0;
|
|
|
|
screen_vp.MinZ = 0;
|
|
|
|
screen_vp.MaxZ = 1;
|
|
|
|
screen_vp.Width = width;
|
2015-11-10 23:09:13 +01:00
|
|
|
screen_vp.Height = height;
|
2018-05-03 22:06:04 +02:00
|
|
|
d3d9_set_viewports(d3d->dev, &screen_vp);
|
|
|
|
d3d9_clear(d3d->dev, 0, 0, D3DCLEAR_TARGET, 0, 1, 0);
|
2014-01-09 18:44:25 +01:00
|
|
|
|
2021-09-25 23:19:45 +01:00
|
|
|
d3d9_set_mvp(d3d->dev, &d3d->mvp_transposed);
|
2016-01-09 04:44:44 +01:00
|
|
|
if (!d3d->renderchain_driver->render(
|
2020-03-08 19:03:57 +01:00
|
|
|
d3d, frame, frame_width, frame_height,
|
2015-04-06 06:46:35 +02:00
|
|
|
pitch, d3d->dev_rotation))
|
2014-01-09 18:44:25 +01:00
|
|
|
{
|
2018-05-13 18:51:05 +02:00
|
|
|
RARCH_ERR("[D3D9]: Failed to render scene.\n");
|
2014-01-09 18:44:25 +01:00
|
|
|
return false;
|
|
|
|
}
|
2020-09-18 11:57:32 -04:00
|
|
|
|
|
|
|
if (black_frame_insertion && !d3d->menu->enabled)
|
|
|
|
{
|
2020-09-19 13:28:21 -04:00
|
|
|
unsigned n;
|
|
|
|
for (n = 0; n < video_info->black_frame_insertion; ++n)
|
2020-09-18 11:57:32 -04:00
|
|
|
{
|
|
|
|
if (!d3d9_swap(d3d, d3d->dev) || d3d->needs_restore)
|
|
|
|
return true;
|
|
|
|
d3d9_clear(d3d->dev, 0, 0, D3DCLEAR_TARGET, 0, 1, 0);
|
|
|
|
}
|
|
|
|
}
|
2014-01-09 18:44:25 +01:00
|
|
|
|
|
|
|
#ifdef HAVE_MENU
|
2014-06-10 02:21:49 +02:00
|
|
|
if (d3d->menu && d3d->menu->enabled)
|
2016-01-07 06:49:10 +01:00
|
|
|
{
|
2021-09-15 00:17:56 +01:00
|
|
|
d3d9_set_mvp(d3d->dev, &d3d->mvp_transposed);
|
2020-03-09 16:15:53 +01:00
|
|
|
d3d9_overlay_render(d3d, width, height, d3d->menu, false);
|
2018-01-15 03:45:37 +01:00
|
|
|
|
2018-01-14 02:21:48 +01:00
|
|
|
d3d->menu_display.offset = 0;
|
2018-05-03 22:06:04 +02:00
|
|
|
d3d9_set_vertex_declaration(d3d->dev, (LPDIRECT3DVERTEXDECLARATION9)d3d->menu_display.decl);
|
|
|
|
d3d9_set_stream_source(d3d->dev, 0, (LPDIRECT3DVERTEXBUFFER9)d3d->menu_display.buffer, 0, sizeof(Vertex));
|
2018-01-15 03:45:37 +01:00
|
|
|
|
2018-05-03 22:06:04 +02:00
|
|
|
d3d9_set_viewports(d3d->dev, &screen_vp);
|
2020-05-19 16:20:43 +02:00
|
|
|
menu_driver_frame(menu_is_alive, video_info);
|
2016-01-07 06:49:10 +01:00
|
|
|
}
|
2020-03-09 16:15:53 +01:00
|
|
|
else if (statistics_show)
|
2018-03-23 17:43:49 +01:00
|
|
|
{
|
|
|
|
if (osd_params)
|
|
|
|
{
|
2018-05-03 22:06:04 +02:00
|
|
|
d3d9_set_viewports(d3d->dev, &screen_vp);
|
|
|
|
d3d9_begin_scene(d3d->dev);
|
2020-03-10 03:24:59 +01:00
|
|
|
font_driver_render_msg(d3d, stat_text,
|
2020-03-09 16:15:53 +01:00
|
|
|
(const struct font_params*)osd_params, NULL);
|
2018-05-03 22:06:04 +02:00
|
|
|
d3d9_end_scene(d3d->dev);
|
2018-03-23 17:43:49 +01:00
|
|
|
}
|
|
|
|
}
|
2014-01-09 18:44:25 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef HAVE_OVERLAY
|
2014-07-25 19:58:45 -05:00
|
|
|
if (d3d->overlays_enabled)
|
2014-01-09 18:44:25 +01:00
|
|
|
{
|
2021-09-25 23:19:45 +01:00
|
|
|
d3d9_set_mvp(d3d->dev, &d3d->mvp_transposed);
|
2017-10-02 06:12:33 +02:00
|
|
|
for (i = 0; i < d3d->overlays_size; i++)
|
2020-03-09 16:15:53 +01:00
|
|
|
d3d9_overlay_render(d3d, width, height, &d3d->overlays[i], true);
|
2014-01-09 18:44:25 +01:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2020-02-17 21:28:42 +01:00
|
|
|
#ifdef HAVE_GFX_WIDGETS
|
2020-08-03 16:33:54 +02:00
|
|
|
if (widgets_active)
|
2020-06-08 05:45:15 +02:00
|
|
|
gfx_widgets_frame(video_info);
|
2019-02-21 17:09:08 +01:00
|
|
|
#endif
|
|
|
|
|
2018-01-14 02:21:48 +01:00
|
|
|
if (msg && *msg)
|
2018-01-15 03:45:37 +01:00
|
|
|
{
|
2018-05-03 22:06:04 +02:00
|
|
|
d3d9_set_viewports(d3d->dev, &screen_vp);
|
|
|
|
d3d9_begin_scene(d3d->dev);
|
2020-03-10 03:24:59 +01:00
|
|
|
font_driver_render_msg(d3d, msg, NULL, NULL);
|
2018-05-03 22:06:04 +02:00
|
|
|
d3d9_end_scene(d3d->dev);
|
2018-01-15 03:45:37 +01:00
|
|
|
}
|
2018-01-14 02:21:48 +01:00
|
|
|
|
2021-06-04 04:30:17 +03:00
|
|
|
win32_update_title();
|
2018-05-03 22:06:04 +02:00
|
|
|
d3d9_swap(d3d, d3d->dev);
|
2014-01-09 18:44:25 +01:00
|
|
|
|
|
|
|
return true;
|
2012-10-26 21:09:30 +02:00
|
|
|
}
|
|
|
|
|
2018-01-23 06:43:03 +01:00
|
|
|
static bool d3d9_read_viewport(void *data, uint8_t *buffer, bool is_idle)
|
2012-10-26 21:09:30 +02:00
|
|
|
{
|
2018-05-17 17:17:08 +02:00
|
|
|
unsigned width, height;
|
|
|
|
D3DLOCKED_RECT rect;
|
|
|
|
LPDIRECT3DSURFACE9 target = NULL;
|
|
|
|
LPDIRECT3DSURFACE9 dest = NULL;
|
|
|
|
bool ret = true;
|
|
|
|
d3d9_video_t *d3d = (d3d9_video_t*)data;
|
|
|
|
LPDIRECT3DDEVICE9 d3dr = d3d->dev;
|
2014-01-09 18:44:25 +01:00
|
|
|
|
2018-05-17 17:17:08 +02:00
|
|
|
video_driver_get_size(&width, &height);
|
|
|
|
|
|
|
|
if (
|
|
|
|
!d3d9_device_get_render_target(d3dr, 0, (void**)&target) ||
|
|
|
|
!d3d9_device_create_offscreen_plain_surface(d3dr, width, height,
|
|
|
|
d3d9_get_xrgb8888_format(),
|
|
|
|
D3DPOOL_SYSTEMMEM, (void**)&dest, NULL) ||
|
2019-01-12 18:51:06 +01:00
|
|
|
!d3d9_device_get_render_target_data(d3dr, target, dest)
|
2018-05-17 17:17:08 +02:00
|
|
|
)
|
|
|
|
{
|
|
|
|
ret = false;
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
2019-01-12 21:16:48 +01:00
|
|
|
if (d3d9_surface_lock_rect(dest, &rect))
|
2018-05-17 17:17:08 +02:00
|
|
|
{
|
|
|
|
unsigned x, y;
|
|
|
|
unsigned pitchpix = rect.Pitch / 4;
|
|
|
|
const uint32_t *pixels = (const uint32_t*)rect.pBits;
|
2014-01-09 18:44:25 +01:00
|
|
|
|
2018-05-17 17:17:08 +02:00
|
|
|
pixels += d3d->final_viewport.X;
|
|
|
|
pixels += (d3d->final_viewport.Height - 1) * pitchpix;
|
|
|
|
pixels -= d3d->final_viewport.Y * pitchpix;
|
|
|
|
|
|
|
|
for (y = 0; y < d3d->final_viewport.Height; y++, pixels -= pitchpix)
|
|
|
|
{
|
|
|
|
for (x = 0; x < d3d->final_viewport.Width; x++)
|
|
|
|
{
|
|
|
|
*buffer++ = (pixels[x] >> 0) & 0xff;
|
|
|
|
*buffer++ = (pixels[x] >> 8) & 0xff;
|
|
|
|
*buffer++ = (pixels[x] >> 16) & 0xff;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-12 21:16:48 +01:00
|
|
|
d3d9_surface_unlock_rect(dest);
|
2018-05-17 17:17:08 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
ret = false;
|
|
|
|
|
|
|
|
end:
|
|
|
|
if (target)
|
|
|
|
d3d9_surface_free(target);
|
|
|
|
if (dest)
|
|
|
|
d3d9_surface_free(dest);
|
|
|
|
return ret;
|
2012-10-26 21:09:30 +02:00
|
|
|
}
|
|
|
|
|
2018-01-23 06:43:03 +01:00
|
|
|
static bool d3d9_set_shader(void *data,
|
2014-09-08 19:28:10 +02:00
|
|
|
enum rarch_shader_type type, const char *path)
|
2012-10-31 16:28:09 +01:00
|
|
|
{
|
2019-07-21 12:13:04 +02:00
|
|
|
#if defined(HAVE_CG) || defined(HAVE_HLSL)
|
2019-06-04 21:52:58 +02:00
|
|
|
d3d9_video_t *d3d = (d3d9_video_t*)data;
|
|
|
|
|
|
|
|
if (!d3d)
|
|
|
|
return false;
|
2017-10-02 01:38:06 +02:00
|
|
|
|
|
|
|
if (!string_is_empty(d3d->shader_path))
|
|
|
|
free(d3d->shader_path);
|
|
|
|
d3d->shader_path = NULL;
|
2014-09-11 20:31:37 +02:00
|
|
|
|
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case RARCH_SHADER_CG:
|
2017-09-13 04:37:29 +02:00
|
|
|
case RARCH_SHADER_HLSL:
|
2019-06-25 10:54:31 +02:00
|
|
|
|
|
|
|
if (type != supported_shader_type)
|
|
|
|
{
|
|
|
|
RARCH_WARN("[D3D9]: Shader preset %s is using unsupported shader type %s, falling back to stock %s.\n",
|
2020-12-26 21:09:27 -05:00
|
|
|
path, video_shader_type_to_str(type), video_shader_type_to_str(supported_shader_type));
|
2019-06-25 10:54:31 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2017-10-02 01:38:06 +02:00
|
|
|
if (!string_is_empty(path))
|
|
|
|
d3d->shader_path = strdup(path);
|
2019-06-25 10:54:31 +02:00
|
|
|
|
2014-09-11 20:31:37 +02:00
|
|
|
break;
|
2019-06-24 23:40:50 +02:00
|
|
|
case RARCH_SHADER_NONE:
|
|
|
|
break;
|
2014-09-11 20:31:37 +02:00
|
|
|
default:
|
2019-06-04 21:52:58 +02:00
|
|
|
RARCH_WARN("[D3D9]: Only Cg shaders are supported. Falling back to stock.\n");
|
2014-09-11 20:31:37 +02:00
|
|
|
}
|
2013-04-13 17:04:28 +02:00
|
|
|
|
2018-01-23 06:43:03 +01:00
|
|
|
if (!d3d9_process_shader(d3d) || !d3d9_restore(d3d))
|
2014-01-09 18:44:25 +01:00
|
|
|
{
|
2019-06-04 21:52:58 +02:00
|
|
|
RARCH_ERR("[D3D9]: Failed to set shader.\n");
|
2016-01-09 04:07:22 +01:00
|
|
|
return false;
|
2014-01-09 18:44:25 +01:00
|
|
|
}
|
|
|
|
|
2016-01-09 04:07:22 +01:00
|
|
|
return true;
|
2019-07-21 12:13:04 +02:00
|
|
|
#else
|
|
|
|
return false;
|
|
|
|
#endif
|
2012-10-31 16:28:09 +01:00
|
|
|
}
|
|
|
|
|
2018-01-23 06:43:03 +01:00
|
|
|
static void d3d9_set_menu_texture_frame(void *data,
|
2013-04-07 19:34:44 +02:00
|
|
|
const void *frame, bool rgb32, unsigned width, unsigned height,
|
|
|
|
float alpha)
|
|
|
|
{
|
2015-03-16 18:33:47 +01:00
|
|
|
D3DLOCKED_RECT d3dlr;
|
2018-05-03 22:03:12 +02:00
|
|
|
d3d9_video_t *d3d = (d3d9_video_t*)data;
|
2014-01-09 18:44:25 +01:00
|
|
|
|
2015-04-06 01:51:58 +02:00
|
|
|
(void)d3dlr;
|
2014-09-11 20:31:37 +02:00
|
|
|
(void)frame;
|
|
|
|
(void)rgb32;
|
|
|
|
(void)width;
|
|
|
|
(void)height;
|
|
|
|
(void)alpha;
|
|
|
|
|
2019-01-10 21:47:15 +01:00
|
|
|
if (!d3d || !d3d->menu)
|
|
|
|
return;
|
|
|
|
|
2019-02-03 15:49:35 -08:00
|
|
|
if ( !d3d->menu->tex ||
|
2017-12-31 17:53:11 +01:00
|
|
|
d3d->menu->tex_w != width ||
|
|
|
|
d3d->menu->tex_h != height)
|
2014-01-09 18:44:25 +01:00
|
|
|
{
|
2019-01-10 21:47:15 +01:00
|
|
|
d3d9_texture_free((LPDIRECT3DTEXTURE9)d3d->menu->tex);
|
2014-09-13 18:17:34 +02:00
|
|
|
|
2018-03-03 15:28:58 +01:00
|
|
|
d3d->menu->tex = d3d9_texture_new(d3d->dev, NULL,
|
2014-09-13 18:42:13 +02:00
|
|
|
width, height, 1,
|
2018-03-03 15:28:58 +01:00
|
|
|
0, d3d9_get_argb8888_format(),
|
2018-01-16 09:11:14 +01:00
|
|
|
D3DPOOL_MANAGED, 0, 0, 0, NULL, NULL, false);
|
2014-09-13 18:42:13 +02:00
|
|
|
|
2014-09-13 18:44:04 +02:00
|
|
|
if (!d3d->menu->tex)
|
2014-01-09 18:44:25 +01:00
|
|
|
{
|
2018-05-13 18:51:05 +02:00
|
|
|
RARCH_ERR("[D3D9]: Failed to create menu texture.\n");
|
2014-01-09 18:44:25 +01:00
|
|
|
return;
|
|
|
|
}
|
2014-09-13 18:42:13 +02:00
|
|
|
|
2018-01-20 06:25:02 +01:00
|
|
|
d3d->menu->tex_w = width;
|
|
|
|
d3d->menu->tex_h = height;
|
2014-01-09 18:44:25 +01:00
|
|
|
}
|
|
|
|
|
2014-06-10 02:21:49 +02:00
|
|
|
d3d->menu->alpha_mod = alpha;
|
2014-01-09 18:44:25 +01:00
|
|
|
|
2018-05-03 15:20:06 +02:00
|
|
|
if (d3d9_lock_rectangle((LPDIRECT3DTEXTURE9)d3d->menu->tex, 0, &d3dlr,
|
2015-11-09 15:39:47 +01:00
|
|
|
NULL, 0, D3DLOCK_NOSYSLOCK))
|
2014-01-09 18:44:25 +01:00
|
|
|
{
|
2015-01-17 06:30:39 +01:00
|
|
|
unsigned h, w;
|
2014-01-09 18:44:25 +01:00
|
|
|
if (rgb32)
|
|
|
|
{
|
2015-01-17 06:30:39 +01:00
|
|
|
uint8_t *dst = (uint8_t*)d3dlr.pBits;
|
2014-01-09 18:44:25 +01:00
|
|
|
const uint32_t *src = (const uint32_t*)frame;
|
2015-01-17 06:30:39 +01:00
|
|
|
|
|
|
|
for (h = 0; h < height; h++, dst += d3dlr.Pitch, src += width)
|
2014-01-09 18:44:25 +01:00
|
|
|
{
|
|
|
|
memcpy(dst, src, width * sizeof(uint32_t));
|
2014-09-08 19:28:10 +02:00
|
|
|
memset(dst + width * sizeof(uint32_t), 0,
|
|
|
|
d3dlr.Pitch - width * sizeof(uint32_t));
|
2014-01-09 18:44:25 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-01-17 06:30:39 +01:00
|
|
|
uint32_t *dst = (uint32_t*)d3dlr.pBits;
|
2014-01-09 18:44:25 +01:00
|
|
|
const uint16_t *src = (const uint16_t*)frame;
|
2015-01-17 06:30:39 +01:00
|
|
|
|
|
|
|
for (h = 0; h < height; h++, dst += d3dlr.Pitch >> 2, src += width)
|
2014-01-09 18:44:25 +01:00
|
|
|
{
|
2015-01-17 06:30:39 +01:00
|
|
|
for (w = 0; w < width; w++)
|
2014-01-09 18:44:25 +01:00
|
|
|
{
|
|
|
|
uint16_t c = src[w];
|
|
|
|
uint32_t r = (c >> 12) & 0xf;
|
|
|
|
uint32_t g = (c >> 8) & 0xf;
|
|
|
|
uint32_t b = (c >> 4) & 0xf;
|
|
|
|
uint32_t a = (c >> 0) & 0xf;
|
2015-04-05 16:34:31 +02:00
|
|
|
r = ((r << 4) | r) << 16;
|
|
|
|
g = ((g << 4) | g) << 8;
|
|
|
|
b = ((b << 4) | b) << 0;
|
|
|
|
a = ((a << 4) | a) << 24;
|
|
|
|
dst[w] = r | g | b | a;
|
2014-01-09 18:44:25 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-10 02:21:49 +02:00
|
|
|
if (d3d->menu)
|
2018-05-03 15:20:06 +02:00
|
|
|
d3d9_unlock_rectangle((LPDIRECT3DTEXTURE9)d3d->menu->tex);
|
2014-01-09 18:44:25 +01:00
|
|
|
}
|
2013-04-07 19:34:44 +02:00
|
|
|
}
|
|
|
|
|
2018-01-23 06:43:03 +01:00
|
|
|
static void d3d9_set_menu_texture_enable(void *data,
|
2014-09-08 19:28:10 +02:00
|
|
|
bool state, bool full_screen)
|
2013-04-07 19:34:44 +02:00
|
|
|
{
|
2018-05-03 22:03:12 +02:00
|
|
|
d3d9_video_t *d3d = (d3d9_video_t*)data;
|
2014-03-07 19:13:20 +01:00
|
|
|
|
2015-05-09 15:52:06 +02:00
|
|
|
if (!d3d || !d3d->menu)
|
2014-03-07 19:13:20 +01:00
|
|
|
return;
|
|
|
|
|
2015-04-05 16:34:31 +02:00
|
|
|
d3d->menu->enabled = state;
|
|
|
|
d3d->menu->fullscreen = full_screen;
|
2013-04-07 19:34:44 +02:00
|
|
|
}
|
|
|
|
|
2018-02-10 21:12:58 +01:00
|
|
|
struct d3d9_texture_info
|
|
|
|
{
|
|
|
|
void *userdata;
|
|
|
|
void *data;
|
|
|
|
enum texture_filter_type type;
|
|
|
|
};
|
|
|
|
|
2018-02-10 21:36:40 +01:00
|
|
|
static void d3d9_video_texture_load_d3d(
|
|
|
|
struct d3d9_texture_info *info,
|
2015-12-20 20:52:23 +01:00
|
|
|
uintptr_t *id)
|
|
|
|
{
|
2018-01-14 02:21:48 +01:00
|
|
|
D3DLOCKED_RECT d3dlr;
|
2018-02-10 21:12:58 +01:00
|
|
|
LPDIRECT3DTEXTURE9 tex = NULL;
|
|
|
|
unsigned usage = 0;
|
|
|
|
bool want_mipmap = false;
|
2018-05-03 22:03:12 +02:00
|
|
|
d3d9_video_t *d3d = (d3d9_video_t*)info->userdata;
|
2018-02-10 21:12:58 +01:00
|
|
|
struct texture_image *ti = (struct texture_image*)info->data;
|
|
|
|
|
|
|
|
if (!ti)
|
|
|
|
return;
|
2018-01-14 02:21:48 +01:00
|
|
|
|
2018-02-10 21:12:58 +01:00
|
|
|
if((info->type == TEXTURE_FILTER_MIPMAP_LINEAR) ||
|
|
|
|
(info->type == TEXTURE_FILTER_MIPMAP_NEAREST))
|
2018-01-16 09:11:14 +01:00
|
|
|
want_mipmap = true;
|
2018-01-14 02:21:48 +01:00
|
|
|
|
2018-03-03 15:28:58 +01:00
|
|
|
tex = (LPDIRECT3DTEXTURE9)d3d9_texture_new(d3d->dev, NULL,
|
2018-01-14 02:21:48 +01:00
|
|
|
ti->width, ti->height, 0,
|
2018-03-03 15:28:58 +01:00
|
|
|
usage, d3d9_get_argb8888_format(),
|
2018-01-20 06:25:02 +01:00
|
|
|
D3DPOOL_MANAGED, 0, 0, 0,
|
2018-01-16 09:11:14 +01:00
|
|
|
NULL, NULL, want_mipmap);
|
2018-01-14 02:21:48 +01:00
|
|
|
|
|
|
|
if (!tex)
|
|
|
|
{
|
2018-05-13 18:51:05 +02:00
|
|
|
RARCH_ERR("[D3D9]: Failed to create texture\n");
|
2018-01-14 02:21:48 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-03-03 15:28:58 +01:00
|
|
|
if (d3d9_lock_rectangle(tex, 0, &d3dlr,
|
2018-01-14 02:21:48 +01:00
|
|
|
NULL, 0, D3DLOCK_NOSYSLOCK))
|
|
|
|
{
|
|
|
|
unsigned i;
|
|
|
|
uint32_t *dst = (uint32_t*)(d3dlr.pBits);
|
|
|
|
const uint32_t *src = ti->pixels;
|
|
|
|
unsigned pitch = d3dlr.Pitch >> 2;
|
|
|
|
|
|
|
|
for (i = 0; i < ti->height; i++, dst += pitch, src += ti->width)
|
|
|
|
memcpy(dst, src, ti->width << 2);
|
2018-03-03 15:28:58 +01:00
|
|
|
d3d9_unlock_rectangle(tex);
|
2018-01-14 02:21:48 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
*id = (uintptr_t)tex;
|
2015-12-20 20:52:23 +01:00
|
|
|
}
|
|
|
|
|
2019-07-20 16:09:39 +02:00
|
|
|
#ifdef HAVE_THREADS
|
2018-11-26 18:09:57 +01:00
|
|
|
static int d3d9_video_texture_load_wrap_d3d(void *data)
|
2015-12-20 20:52:23 +01:00
|
|
|
{
|
2015-12-20 21:08:03 +01:00
|
|
|
uintptr_t id = 0;
|
2018-02-10 21:12:58 +01:00
|
|
|
struct d3d9_texture_info *info = (struct d3d9_texture_info*)data;
|
|
|
|
if (!info)
|
|
|
|
return 0;
|
|
|
|
d3d9_video_texture_load_d3d(info, &id);
|
2018-11-26 18:09:57 +01:00
|
|
|
return id;
|
2015-12-20 20:52:23 +01:00
|
|
|
}
|
2019-07-20 16:09:39 +02:00
|
|
|
#endif
|
2015-12-20 20:52:23 +01:00
|
|
|
|
2018-01-23 06:43:03 +01:00
|
|
|
static uintptr_t d3d9_load_texture(void *video_data, void *data,
|
2015-12-20 20:52:23 +01:00
|
|
|
bool threaded, enum texture_filter_type filter_type)
|
|
|
|
{
|
2015-12-20 21:08:03 +01:00
|
|
|
uintptr_t id = 0;
|
2018-02-10 22:27:38 +01:00
|
|
|
struct d3d9_texture_info info;
|
2015-12-20 20:52:23 +01:00
|
|
|
|
2018-02-10 22:27:38 +01:00
|
|
|
info.userdata = video_data;
|
|
|
|
info.data = data;
|
|
|
|
info.type = filter_type;
|
2015-12-20 20:52:23 +01:00
|
|
|
|
2019-07-20 16:09:39 +02:00
|
|
|
#ifdef HAVE_THREADS
|
2018-02-10 21:12:58 +01:00
|
|
|
if (threaded)
|
2019-01-10 22:52:13 +01:00
|
|
|
return video_thread_texture_load(&info,
|
2018-02-10 21:36:40 +01:00
|
|
|
d3d9_video_texture_load_wrap_d3d);
|
2019-07-20 16:09:39 +02:00
|
|
|
#endif
|
2015-12-20 20:52:23 +01:00
|
|
|
|
2018-02-10 22:27:38 +01:00
|
|
|
d3d9_video_texture_load_d3d(&info, &id);
|
2015-12-20 21:08:03 +01:00
|
|
|
return id;
|
2015-12-20 20:52:23 +01:00
|
|
|
}
|
|
|
|
|
2020-07-27 10:15:28 +02:00
|
|
|
static void d3d9_unload_texture(void *data,
|
|
|
|
bool threaded, uintptr_t id)
|
2015-12-20 20:52:23 +01:00
|
|
|
{
|
2018-01-25 04:28:50 +01:00
|
|
|
LPDIRECT3DTEXTURE9 texid;
|
2016-01-08 17:51:03 +01:00
|
|
|
if (!id)
|
2019-06-24 23:40:50 +02:00
|
|
|
return;
|
2016-01-08 17:51:03 +01:00
|
|
|
|
2018-01-25 04:28:50 +01:00
|
|
|
texid = (LPDIRECT3DTEXTURE9)id;
|
2018-03-03 15:28:58 +01:00
|
|
|
d3d9_texture_free(texid);
|
2015-12-20 20:52:23 +01:00
|
|
|
}
|
|
|
|
|
2018-03-02 16:53:15 +01:00
|
|
|
static void d3d9_set_video_mode(void *data,
|
|
|
|
unsigned width, unsigned height,
|
|
|
|
bool fullscreen)
|
|
|
|
{
|
|
|
|
#ifndef _XBOX
|
2020-01-04 15:40:02 +01:00
|
|
|
win32_show_cursor(data, !fullscreen);
|
2018-03-02 16:53:15 +01:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2018-04-23 14:15:21 +02:00
|
|
|
static uint32_t d3d9_get_flags(void *data)
|
|
|
|
{
|
2019-06-24 23:40:50 +02:00
|
|
|
uint32_t flags = 0;
|
2018-04-23 14:15:21 +02:00
|
|
|
|
|
|
|
BIT32_SET(flags, GFX_CTX_FLAGS_BLACK_FRAME_INSERTION);
|
2018-04-24 15:14:06 +02:00
|
|
|
BIT32_SET(flags, GFX_CTX_FLAGS_MENU_FRAME_FILTERING);
|
2019-06-25 10:54:31 +02:00
|
|
|
|
|
|
|
if (supported_shader_type == RARCH_SHADER_CG)
|
|
|
|
BIT32_SET(flags, GFX_CTX_FLAGS_SHADERS_CG);
|
|
|
|
else if (supported_shader_type == RARCH_SHADER_HLSL)
|
|
|
|
BIT32_SET(flags, GFX_CTX_FLAGS_SHADERS_HLSL);
|
2018-04-23 14:15:21 +02:00
|
|
|
|
|
|
|
return flags;
|
|
|
|
}
|
|
|
|
|
2018-01-23 06:43:03 +01:00
|
|
|
static const video_poke_interface_t d3d9_poke_interface = {
|
2018-04-23 14:15:21 +02:00
|
|
|
d3d9_get_flags,
|
2018-01-23 06:43:03 +01:00
|
|
|
d3d9_load_texture,
|
|
|
|
d3d9_unload_texture,
|
2018-03-02 16:53:15 +01:00
|
|
|
d3d9_set_video_mode,
|
2018-12-28 12:41:38 +01:00
|
|
|
#if defined(_XBOX) || defined(__WINRT__)
|
2018-05-14 01:50:58 +02:00
|
|
|
NULL,
|
2018-04-25 14:20:37 +02:00
|
|
|
#else
|
2018-12-28 12:41:38 +01:00
|
|
|
/* UWP does not expose this information easily */
|
2018-04-15 19:33:38 -05:00
|
|
|
win32_get_refresh_rate,
|
2018-04-25 14:20:37 +02:00
|
|
|
#endif
|
2018-04-15 11:12:56 -05:00
|
|
|
NULL,
|
2015-02-24 20:06:58 +01:00
|
|
|
NULL, /* get_video_output_size */
|
2015-02-24 21:36:23 +01:00
|
|
|
NULL, /* get_video_output_prev */
|
|
|
|
NULL, /* get_video_output_next */
|
2015-04-25 02:35:06 +02:00
|
|
|
NULL, /* get_current_framebuffer */
|
|
|
|
NULL, /* get_proc_address */
|
2018-01-23 06:43:03 +01:00
|
|
|
d3d9_set_aspect_ratio,
|
|
|
|
d3d9_apply_state_changes,
|
|
|
|
d3d9_set_menu_texture_frame,
|
|
|
|
d3d9_set_menu_texture_enable,
|
|
|
|
d3d9_set_osd_msg,
|
2013-04-07 19:34:44 +02:00
|
|
|
|
2020-01-04 15:40:02 +01:00
|
|
|
win32_show_cursor,
|
2018-01-30 22:29:57 +01:00
|
|
|
NULL, /* grab_mouse_toggle */
|
|
|
|
NULL, /* get_current_shader */
|
|
|
|
NULL, /* get_current_software_framebuffer */
|
2021-09-03 06:15:25 +02:00
|
|
|
NULL, /* get_hw_render_interface */
|
|
|
|
NULL, /* set_hdr_max_nits */
|
|
|
|
NULL, /* set_hdr_paper_white_nits */
|
|
|
|
NULL, /* set_hdr_contrast */
|
|
|
|
NULL /* set_hdr_expand_gamut */
|
2013-04-07 19:34:44 +02:00
|
|
|
};
|
|
|
|
|
2018-01-23 06:43:03 +01:00
|
|
|
static void d3d9_get_poke_interface(void *data,
|
2014-09-08 19:28:10 +02:00
|
|
|
const video_poke_interface_t **iface)
|
2013-04-07 19:34:44 +02:00
|
|
|
{
|
2018-01-23 06:43:03 +01:00
|
|
|
*iface = &d3d9_poke_interface;
|
2013-04-07 19:34:44 +02:00
|
|
|
}
|
|
|
|
|
2018-03-02 16:46:32 +01:00
|
|
|
#ifdef _XBOX
|
2020-07-27 13:16:14 +02:00
|
|
|
static bool d3d9_has_windowed(void *data) { return false; }
|
2018-03-02 16:46:32 +01:00
|
|
|
#else
|
2020-07-27 13:16:14 +02:00
|
|
|
static bool d3d9_has_windowed(void *data) { return true; }
|
2018-03-02 16:46:32 +01:00
|
|
|
#endif
|
|
|
|
|
2020-02-17 21:28:42 +01:00
|
|
|
#ifdef HAVE_GFX_WIDGETS
|
2020-02-17 01:43:40 +01:00
|
|
|
static bool d3d9_gfx_widgets_enabled(void *data)
|
2019-02-22 03:13:11 +01:00
|
|
|
{
|
2019-06-24 14:53:03 +02:00
|
|
|
return false; /* currently disabled due to memory issues */
|
2019-02-22 03:13:11 +01:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2018-01-23 02:55:33 +01:00
|
|
|
video_driver_t video_d3d9 = {
|
2018-01-23 06:43:03 +01:00
|
|
|
d3d9_init,
|
|
|
|
d3d9_frame,
|
|
|
|
d3d9_set_nonblock_state,
|
|
|
|
d3d9_alive,
|
2017-05-13 19:19:49 +02:00
|
|
|
NULL, /* focus */
|
2018-01-23 06:43:03 +01:00
|
|
|
d3d9_suppress_screensaver,
|
2018-03-02 16:46:32 +01:00
|
|
|
d3d9_has_windowed,
|
2018-01-23 06:43:03 +01:00
|
|
|
d3d9_set_shader,
|
|
|
|
d3d9_free,
|
2018-01-23 02:55:33 +01:00
|
|
|
"d3d9",
|
2018-01-23 06:43:03 +01:00
|
|
|
d3d9_set_viewport,
|
|
|
|
d3d9_set_rotation,
|
|
|
|
d3d9_viewport_info,
|
|
|
|
d3d9_read_viewport,
|
2017-05-13 19:19:49 +02:00
|
|
|
NULL, /* read_frame_raw */
|
2013-03-27 15:55:59 +01:00
|
|
|
#ifdef HAVE_OVERLAY
|
2018-01-23 06:43:03 +01:00
|
|
|
d3d9_get_overlay_interface,
|
2019-04-01 04:00:58 +01:00
|
|
|
#endif
|
|
|
|
#ifdef HAVE_VIDEO_LAYOUT
|
|
|
|
NULL,
|
2013-03-27 15:55:59 +01:00
|
|
|
#endif
|
2019-02-22 03:13:11 +01:00
|
|
|
d3d9_get_poke_interface,
|
|
|
|
NULL, /* wrap_type_to_enum */
|
2020-02-17 21:28:42 +01:00
|
|
|
#ifdef HAVE_GFX_WIDGETS
|
2020-02-17 01:43:40 +01:00
|
|
|
d3d9_gfx_widgets_enabled
|
2019-02-22 03:13:11 +01:00
|
|
|
#endif
|
2014-01-22 16:38:42 +01:00
|
|
|
};
|