2018-12-28 12:41:38 +01:00
|
|
|
/* RetroArch - A frontend for libretro.
|
2018-01-21 04:10:45 +01:00
|
|
|
* Copyright (C) 2014-2018 - Ali Bouhlel
|
2019-06-18 16:33:37 -04:00
|
|
|
* Copyright (C) 2016-2019 - Brad Parker
|
2018-01-21 04:10:45 +01: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/>.
|
|
|
|
*/
|
|
|
|
|
2021-09-26 14:16:09 +02:00
|
|
|
/* Direct3D 11 driver.
|
|
|
|
*
|
|
|
|
* Minimum version : Direct3D 11.0 (Feature Level 11.0) (2009)
|
|
|
|
* Minimum OS : Windows Vista, Windows 7
|
|
|
|
* Recommended OS : Windows 7 and/or later
|
|
|
|
*/
|
|
|
|
|
2018-02-04 20:03:27 +01:00
|
|
|
#define CINTERFACE
|
2019-03-07 19:17:54 -05:00
|
|
|
#define COBJMACROS
|
2018-02-04 20:03:27 +01:00
|
|
|
|
2018-01-21 04:10:45 +01:00
|
|
|
#include <assert.h>
|
|
|
|
|
2018-01-24 01:29:45 +01:00
|
|
|
#include <string/stdstring.h>
|
2018-01-23 18:04:55 +01:00
|
|
|
#include <gfx/scaler/pixconv.h>
|
2018-04-17 21:29:02 +02:00
|
|
|
#include <retro_miscellaneous.h>
|
2018-01-31 01:08:36 +01:00
|
|
|
#include <file/file_path.h>
|
2019-03-07 19:17:54 -05:00
|
|
|
#include <encodings/utf.h>
|
2019-06-18 16:33:37 -04:00
|
|
|
#include <lists/string_list.h>
|
2019-07-10 05:39:50 +02:00
|
|
|
#include <formats/image.h>
|
|
|
|
|
2019-03-07 19:17:54 -05:00
|
|
|
#include <dxgi.h>
|
2018-01-21 04:10:45 +01:00
|
|
|
|
2019-02-07 00:43:36 +01:00
|
|
|
#ifdef HAVE_MENU
|
|
|
|
#include "../../menu/menu_driver.h"
|
|
|
|
#endif
|
2020-02-17 21:28:42 +01:00
|
|
|
#ifdef HAVE_GFX_WIDGETS
|
|
|
|
#include "../gfx_widgets.h"
|
2019-02-07 00:43:36 +01:00
|
|
|
#endif
|
|
|
|
|
2018-01-24 01:29:45 +01:00
|
|
|
#include "../../driver.h"
|
|
|
|
#include "../../verbosity.h"
|
2019-02-15 15:58:52 -05:00
|
|
|
#include "../../configuration.h"
|
2018-10-10 19:02:36 -05:00
|
|
|
#include "../../retroarch.h"
|
2018-01-24 20:51:19 +01:00
|
|
|
#include "../font_driver.h"
|
2018-01-24 01:29:45 +01:00
|
|
|
#include "../common/win32_common.h"
|
2018-01-31 01:08:36 +01:00
|
|
|
#include "../../performance_counters.h"
|
|
|
|
#include "../../menu/menu_driver.h"
|
|
|
|
#include "../video_shader_parse.h"
|
2019-08-18 18:55:22 +02:00
|
|
|
#include "../drivers_shader/slang_process.h"
|
2020-07-01 21:04:05 +02:00
|
|
|
#ifdef HAVE_REWIND
|
2020-10-15 05:29:20 +02:00
|
|
|
#include "../../state_manager.h"
|
2020-07-01 21:04:05 +02:00
|
|
|
#endif
|
2018-01-31 01:08:36 +01:00
|
|
|
|
2018-12-30 04:51:03 +01:00
|
|
|
#include "../common/d3d_common.h"
|
2018-01-24 01:29:45 +01:00
|
|
|
#include "../common/d3d11_common.h"
|
|
|
|
#include "../common/dxgi_common.h"
|
|
|
|
#include "../common/d3dcompiler_common.h"
|
2018-02-03 17:01:47 +01:00
|
|
|
#ifdef HAVE_SLANG
|
2018-01-31 01:08:36 +01:00
|
|
|
#include "../drivers_shader/slang_process.h"
|
2018-02-03 17:01:47 +01:00
|
|
|
#endif
|
2018-01-24 01:29:45 +01:00
|
|
|
|
2018-12-28 12:41:38 +01:00
|
|
|
#ifdef __WINRT__
|
|
|
|
#include "../../uwp/uwp_func.h"
|
2021-06-22 00:41:56 +02:00
|
|
|
#else
|
2021-06-16 16:07:38 +02:00
|
|
|
const GUID DECLSPEC_SELECTANY libretro_IID_IDXGIFactory5 = { 0x7632e1f5,0xee65,0x4dca, { 0x87,0xfd,0x84,0xcd,0x75,0xf8,0x83,0x8d } };
|
|
|
|
#endif
|
|
|
|
|
2019-06-19 18:05:21 +02:00
|
|
|
/* Temporary workaround for d3d11 not being able to poll flags during init */
|
|
|
|
static gfx_ctx_driver_t d3d11_fake_context;
|
|
|
|
|
2018-03-28 10:33:37 -05:00
|
|
|
static D3D11Device cached_device_d3d11;
|
2018-03-26 17:44:08 +01:00
|
|
|
static D3D_FEATURE_LEVEL cached_supportedFeatureLevel;
|
2020-12-15 22:56:06 +01:00
|
|
|
static D3D11DeviceContext cached_context_d3d11;
|
2019-06-18 16:33:37 -04:00
|
|
|
|
2020-08-16 03:11:00 +02:00
|
|
|
static uint32_t d3d11_get_flags(void *data)
|
|
|
|
{
|
|
|
|
uint32_t flags = 0;
|
|
|
|
|
|
|
|
BIT32_SET(flags, GFX_CTX_FLAGS_MENU_FRAME_FILTERING);
|
2021-12-26 05:56:44 +02:00
|
|
|
BIT32_SET(flags, GFX_CTX_FLAGS_OVERLAY_BEHIND_MENU_SUPPORTED);
|
2020-08-16 03:11:00 +02:00
|
|
|
#if defined(HAVE_SLANG) && defined(HAVE_SPIRV_CROSS)
|
|
|
|
BIT32_SET(flags, GFX_CTX_FLAGS_SHADERS_SLANG);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return flags;
|
|
|
|
}
|
|
|
|
|
2018-02-12 01:19:43 +01:00
|
|
|
#ifdef HAVE_OVERLAY
|
|
|
|
static void d3d11_free_overlays(d3d11_video_t* d3d11)
|
|
|
|
{
|
|
|
|
unsigned i;
|
2018-04-21 05:20:22 +02:00
|
|
|
for (i = 0; i < (unsigned)d3d11->overlays.count; i++)
|
2018-02-12 01:19:43 +01:00
|
|
|
d3d11_release_texture(&d3d11->overlays.textures[i]);
|
|
|
|
|
|
|
|
Release(d3d11->overlays.vbo);
|
|
|
|
}
|
|
|
|
|
2020-08-16 03:11:00 +02:00
|
|
|
static void d3d11_overlay_vertex_geom(
|
|
|
|
void* data, unsigned index,
|
|
|
|
float x, float y, float w, float h)
|
2018-02-12 01:19:43 +01:00
|
|
|
{
|
|
|
|
D3D11_MAPPED_SUBRESOURCE mapped_vbo;
|
|
|
|
d3d11_video_t* d3d11 = (d3d11_video_t*)data;
|
|
|
|
|
|
|
|
if (!d3d11)
|
|
|
|
return;
|
|
|
|
|
|
|
|
D3D11MapBuffer(
|
|
|
|
d3d11->context, d3d11->overlays.vbo, 0, D3D11_MAP_WRITE_NO_OVERWRITE, 0, &mapped_vbo);
|
|
|
|
{
|
|
|
|
d3d11_sprite_t* sprites = (d3d11_sprite_t*)mapped_vbo.pData;
|
|
|
|
sprites[index].pos.x = x;
|
|
|
|
sprites[index].pos.y = y;
|
|
|
|
sprites[index].pos.w = w;
|
|
|
|
sprites[index].pos.h = h;
|
|
|
|
}
|
|
|
|
D3D11UnmapBuffer(d3d11->context, d3d11->overlays.vbo, 0);
|
|
|
|
}
|
|
|
|
|
2020-08-16 03:11:00 +02:00
|
|
|
static void d3d11_overlay_tex_geom(
|
|
|
|
void* data, unsigned index,
|
|
|
|
float u, float v, float w, float h)
|
2018-02-12 01:19:43 +01:00
|
|
|
{
|
|
|
|
D3D11_MAPPED_SUBRESOURCE mapped_vbo;
|
|
|
|
d3d11_video_t* d3d11 = (d3d11_video_t*)data;
|
|
|
|
|
|
|
|
if (!d3d11)
|
|
|
|
return;
|
|
|
|
|
|
|
|
D3D11MapBuffer(
|
|
|
|
d3d11->context, d3d11->overlays.vbo, 0, D3D11_MAP_WRITE_NO_OVERWRITE, 0, &mapped_vbo);
|
|
|
|
{
|
|
|
|
d3d11_sprite_t* sprites = (d3d11_sprite_t*)mapped_vbo.pData;
|
|
|
|
sprites[index].coords.u = u;
|
|
|
|
sprites[index].coords.v = v;
|
|
|
|
sprites[index].coords.w = w;
|
|
|
|
sprites[index].coords.h = h;
|
|
|
|
}
|
|
|
|
D3D11UnmapBuffer(d3d11->context, d3d11->overlays.vbo, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void d3d11_overlay_set_alpha(void* data, unsigned index, float mod)
|
|
|
|
{
|
|
|
|
D3D11_MAPPED_SUBRESOURCE mapped_vbo;
|
|
|
|
d3d11_video_t* d3d11 = (d3d11_video_t*)data;
|
|
|
|
|
|
|
|
if (!d3d11)
|
|
|
|
return;
|
|
|
|
|
|
|
|
D3D11MapBuffer(
|
|
|
|
d3d11->context, d3d11->overlays.vbo, 0, D3D11_MAP_WRITE_NO_OVERWRITE, 0, &mapped_vbo);
|
|
|
|
{
|
|
|
|
d3d11_sprite_t* sprites = (d3d11_sprite_t*)mapped_vbo.pData;
|
|
|
|
sprites[index].colors[0] = DXGI_COLOR_RGBA(0xFF, 0xFF, 0xFF, mod * 0xFF);
|
|
|
|
sprites[index].colors[1] = sprites[index].colors[0];
|
|
|
|
sprites[index].colors[2] = sprites[index].colors[0];
|
|
|
|
sprites[index].colors[3] = sprites[index].colors[0];
|
|
|
|
}
|
|
|
|
D3D11UnmapBuffer(d3d11->context, d3d11->overlays.vbo, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool d3d11_overlay_load(void* data, const void* image_data, unsigned num_images)
|
|
|
|
{
|
2018-04-09 18:53:26 +02:00
|
|
|
D3D11_BUFFER_DESC desc;
|
|
|
|
D3D11_MAPPED_SUBRESOURCE mapped_vbo;
|
2018-04-21 05:20:22 +02:00
|
|
|
unsigned i;
|
2018-02-12 01:19:43 +01:00
|
|
|
d3d11_sprite_t* sprites;
|
|
|
|
d3d11_video_t* d3d11 = (d3d11_video_t*)data;
|
|
|
|
const struct texture_image* images = (const struct texture_image*)image_data;
|
|
|
|
|
|
|
|
if (!d3d11)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
d3d11_free_overlays(d3d11);
|
|
|
|
d3d11->overlays.count = num_images;
|
2018-04-09 18:53:26 +02:00
|
|
|
d3d11->overlays.textures = (d3d11_texture_t*)calloc(
|
|
|
|
num_images, sizeof(d3d11_texture_t));
|
2018-02-12 01:19:43 +01:00
|
|
|
|
2018-04-09 18:53:26 +02:00
|
|
|
desc.ByteWidth = sizeof(d3d11_sprite_t) * num_images;
|
|
|
|
desc.Usage = D3D11_USAGE_DYNAMIC;
|
|
|
|
desc.BindFlags = D3D11_BIND_VERTEX_BUFFER;
|
|
|
|
desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
|
|
|
|
desc.MiscFlags = 0;
|
|
|
|
desc.StructureByteStride = 0;
|
|
|
|
D3D11CreateBuffer(d3d11->device, &desc, NULL, &d3d11->overlays.vbo);
|
2018-02-12 01:19:43 +01:00
|
|
|
|
|
|
|
D3D11MapBuffer(d3d11->context, d3d11->overlays.vbo, 0, D3D11_MAP_WRITE_DISCARD, 0, &mapped_vbo);
|
2018-04-09 18:53:26 +02:00
|
|
|
sprites = (d3d11_sprite_t*)mapped_vbo.pData;
|
2018-02-12 01:19:43 +01:00
|
|
|
|
|
|
|
for (i = 0; i < num_images; i++)
|
|
|
|
{
|
|
|
|
|
|
|
|
d3d11->overlays.textures[i].desc.Width = images[i].width;
|
|
|
|
d3d11->overlays.textures[i].desc.Height = images[i].height;
|
|
|
|
d3d11->overlays.textures[i].desc.Format = DXGI_FORMAT_B8G8R8A8_UNORM;
|
|
|
|
|
|
|
|
d3d11_init_texture(d3d11->device, &d3d11->overlays.textures[i]);
|
|
|
|
|
|
|
|
d3d11_update_texture(
|
2018-04-09 18:53:26 +02:00
|
|
|
d3d11->context, images[i].width,
|
|
|
|
images[i].height, 0, DXGI_FORMAT_B8G8R8A8_UNORM,
|
2018-02-12 01:19:43 +01:00
|
|
|
images[i].pixels, &d3d11->overlays.textures[i]);
|
|
|
|
|
2018-04-09 18:53:26 +02:00
|
|
|
sprites[i].pos.x = 0.0f;
|
|
|
|
sprites[i].pos.y = 0.0f;
|
|
|
|
sprites[i].pos.w = 1.0f;
|
|
|
|
sprites[i].pos.h = 1.0f;
|
2018-02-12 01:19:43 +01:00
|
|
|
|
2018-04-09 18:53:26 +02:00
|
|
|
sprites[i].coords.u = 0.0f;
|
|
|
|
sprites[i].coords.v = 0.0f;
|
|
|
|
sprites[i].coords.w = 1.0f;
|
|
|
|
sprites[i].coords.h = 1.0f;
|
2018-02-12 01:19:43 +01:00
|
|
|
|
|
|
|
sprites[i].params.scaling = 1;
|
|
|
|
sprites[i].params.rotation = 0;
|
|
|
|
|
2018-04-09 18:53:26 +02:00
|
|
|
sprites[i].colors[0] = 0xFFFFFFFF;
|
|
|
|
sprites[i].colors[1] = sprites[i].colors[0];
|
|
|
|
sprites[i].colors[2] = sprites[i].colors[0];
|
|
|
|
sprites[i].colors[3] = sprites[i].colors[0];
|
2018-02-12 01:19:43 +01:00
|
|
|
}
|
|
|
|
D3D11UnmapBuffer(d3d11->context, d3d11->overlays.vbo, 0);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void d3d11_overlay_enable(void* data, bool state)
|
|
|
|
{
|
|
|
|
d3d11_video_t* d3d11 = (d3d11_video_t*)data;
|
|
|
|
|
|
|
|
if (!d3d11)
|
|
|
|
return;
|
|
|
|
|
|
|
|
d3d11->overlays.enabled = state;
|
2020-01-04 15:40:02 +01:00
|
|
|
win32_show_cursor(d3d11, state);
|
2018-02-12 01:19:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void d3d11_overlay_full_screen(void* data, bool enable)
|
|
|
|
{
|
|
|
|
d3d11_video_t* d3d11 = (d3d11_video_t*)data;
|
|
|
|
|
|
|
|
if (!d3d11)
|
|
|
|
return;
|
|
|
|
|
|
|
|
d3d11->overlays.fullscreen = enable;
|
|
|
|
}
|
|
|
|
|
2020-08-16 03:11:00 +02:00
|
|
|
static void d3d11_get_overlay_interface(
|
|
|
|
void* data, const video_overlay_interface_t** iface)
|
2018-02-12 01:19:43 +01:00
|
|
|
{
|
|
|
|
static const video_overlay_interface_t overlay_interface = {
|
|
|
|
d3d11_overlay_enable, d3d11_overlay_load, d3d11_overlay_tex_geom,
|
|
|
|
d3d11_overlay_vertex_geom, d3d11_overlay_full_screen, d3d11_overlay_set_alpha,
|
|
|
|
};
|
|
|
|
|
|
|
|
*iface = &overlay_interface;
|
|
|
|
}
|
2021-12-26 05:56:44 +02:00
|
|
|
|
|
|
|
static void d3d11_render_overlay(void *data)
|
|
|
|
{
|
|
|
|
unsigned i;
|
|
|
|
d3d11_video_t* d3d11 = (d3d11_video_t*)data;
|
|
|
|
|
|
|
|
if (!d3d11)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (d3d11->overlays.fullscreen)
|
|
|
|
D3D11SetViewports(d3d11->context, 1, &d3d11->viewport);
|
|
|
|
else
|
|
|
|
D3D11SetViewports(d3d11->context, 1, &d3d11->frame.viewport);
|
|
|
|
|
|
|
|
D3D11SetBlendState(d3d11->context, d3d11->blend_enable, NULL, D3D11_DEFAULT_SAMPLE_MASK);
|
|
|
|
D3D11SetVertexBuffer(d3d11->context, 0, d3d11->overlays.vbo, sizeof(d3d11_sprite_t), 0);
|
|
|
|
D3D11SetPShaderSamplers(
|
|
|
|
d3d11->context, 0, 1, &d3d11->samplers[RARCH_FILTER_UNSPEC][RARCH_WRAP_DEFAULT]);
|
|
|
|
|
|
|
|
for (i = 0; i < (unsigned)d3d11->overlays.count; i++)
|
|
|
|
{
|
|
|
|
D3D11SetPShaderResources(d3d11->context, 0, 1, &d3d11->overlays.textures[i].view);
|
|
|
|
D3D11Draw(d3d11->context, 1, i);
|
|
|
|
}
|
|
|
|
}
|
2018-02-12 01:19:43 +01:00
|
|
|
#endif
|
|
|
|
|
2021-09-03 06:15:25 +02:00
|
|
|
#ifdef HAVE_DXGI_HDR
|
|
|
|
static void d3d11_set_hdr_max_nits(void *data, float max_nits)
|
|
|
|
{
|
|
|
|
D3D11_MAPPED_SUBRESOURCE mapped_ubo;
|
|
|
|
d3d11_video_t* d3d11 = (d3d11_video_t*)data;
|
|
|
|
|
|
|
|
d3d11->hdr.max_output_nits = max_nits;
|
2021-09-13 15:54:50 +01:00
|
|
|
d3d11->hdr.ubo_values.max_nits = max_nits;
|
2021-09-03 06:15:25 +02:00
|
|
|
|
|
|
|
D3D11MapBuffer(d3d11->context, d3d11->hdr.ubo,
|
|
|
|
0, D3D11_MAP_WRITE_NO_OVERWRITE, 0, &mapped_ubo);
|
|
|
|
{
|
|
|
|
dxgi_hdr_uniform_t *ubo = (dxgi_hdr_uniform_t*)mapped_ubo.pData;
|
|
|
|
*ubo = d3d11->hdr.ubo_values;
|
|
|
|
}
|
|
|
|
D3D11UnmapBuffer(d3d11->context, d3d11->hdr.ubo, 0);
|
|
|
|
|
|
|
|
dxgi_set_hdr_metadata(
|
|
|
|
d3d11->swapChain,
|
|
|
|
d3d11->hdr.support,
|
|
|
|
d3d11->chain_bit_depth,
|
|
|
|
d3d11->chain_color_space,
|
|
|
|
d3d11->hdr.max_output_nits,
|
|
|
|
d3d11->hdr.min_output_nits,
|
|
|
|
d3d11->hdr.max_cll,
|
|
|
|
d3d11->hdr.max_fall);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void d3d11_set_hdr_paper_white_nits(void* data, float paper_white_nits)
|
|
|
|
{
|
|
|
|
D3D11_MAPPED_SUBRESOURCE mapped_ubo;
|
|
|
|
dxgi_hdr_uniform_t *ubo = NULL;
|
|
|
|
d3d11_video_t *d3d11 = (d3d11_video_t*)data;
|
|
|
|
|
2021-09-13 15:54:50 +01:00
|
|
|
d3d11->hdr.ubo_values.paper_white_nits = paper_white_nits;
|
2021-09-03 06:15:25 +02:00
|
|
|
|
|
|
|
D3D11MapBuffer(d3d11->context, d3d11->hdr.ubo,
|
|
|
|
0, D3D11_MAP_WRITE_DISCARD, 0, &mapped_ubo);
|
|
|
|
ubo = (dxgi_hdr_uniform_t*)mapped_ubo.pData;
|
|
|
|
*ubo = d3d11->hdr.ubo_values;
|
|
|
|
D3D11UnmapBuffer(d3d11->context, d3d11->hdr.ubo, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void d3d11_set_hdr_contrast(void* data, float contrast)
|
|
|
|
{
|
|
|
|
D3D11_MAPPED_SUBRESOURCE mapped_ubo;
|
|
|
|
dxgi_hdr_uniform_t *ubo = NULL;
|
|
|
|
d3d11_video_t* d3d11 = (d3d11_video_t*)data;
|
|
|
|
|
|
|
|
d3d11->hdr.ubo_values.contrast = contrast;
|
|
|
|
|
|
|
|
D3D11MapBuffer(d3d11->context, d3d11->hdr.ubo,
|
|
|
|
0, D3D11_MAP_WRITE_DISCARD, 0, &mapped_ubo);
|
|
|
|
ubo = (dxgi_hdr_uniform_t*)mapped_ubo.pData;
|
|
|
|
*ubo = d3d11->hdr.ubo_values;
|
|
|
|
D3D11UnmapBuffer(d3d11->context, d3d11->hdr.ubo, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void d3d11_set_hdr_expand_gamut(void* data, bool expand_gamut)
|
|
|
|
{
|
|
|
|
D3D11_MAPPED_SUBRESOURCE mapped_ubo;
|
|
|
|
dxgi_hdr_uniform_t *ubo = NULL;
|
|
|
|
d3d11_video_t* d3d11 = (d3d11_video_t*)data;
|
|
|
|
|
2021-12-22 01:17:17 +00:00
|
|
|
d3d11->hdr.ubo_values.expand_gamut = expand_gamut ? 1.0f : 0.0f;
|
|
|
|
|
|
|
|
D3D11MapBuffer(d3d11->context, d3d11->hdr.ubo, 0, D3D11_MAP_WRITE_DISCARD, 0, &mapped_ubo);
|
|
|
|
ubo = (dxgi_hdr_uniform_t*)mapped_ubo.pData;
|
|
|
|
*ubo = d3d11->hdr.ubo_values;
|
|
|
|
D3D11UnmapBuffer(d3d11->context, d3d11->hdr.ubo, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void d3d11_set_hdr_inverse_tonemap(d3d11_video_t* d3d11, bool inverse_tonemap)
|
|
|
|
{
|
|
|
|
D3D11_MAPPED_SUBRESOURCE mapped_ubo;
|
|
|
|
dxgi_hdr_uniform_t *ubo = NULL;
|
|
|
|
|
|
|
|
d3d11->hdr.ubo_values.inverse_tonemap = inverse_tonemap ? 1.0f : 0.0f;
|
|
|
|
|
|
|
|
D3D11MapBuffer(d3d11->context, d3d11->hdr.ubo, 0, D3D11_MAP_WRITE_DISCARD, 0, &mapped_ubo);
|
|
|
|
ubo = (dxgi_hdr_uniform_t*)mapped_ubo.pData;
|
|
|
|
*ubo = d3d11->hdr.ubo_values;
|
|
|
|
D3D11UnmapBuffer(d3d11->context, d3d11->hdr.ubo, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void d3d11_set_hdr10(d3d11_video_t* d3d11, bool hdr10)
|
|
|
|
{
|
|
|
|
D3D11_MAPPED_SUBRESOURCE mapped_ubo;
|
|
|
|
dxgi_hdr_uniform_t *ubo = NULL;
|
|
|
|
|
|
|
|
d3d11->hdr.ubo_values.hdr10 = hdr10 ? 1.0f : 0.0f;
|
2021-09-03 06:15:25 +02:00
|
|
|
|
|
|
|
D3D11MapBuffer(d3d11->context, d3d11->hdr.ubo, 0, D3D11_MAP_WRITE_DISCARD, 0, &mapped_ubo);
|
|
|
|
ubo = (dxgi_hdr_uniform_t*)mapped_ubo.pData;
|
|
|
|
*ubo = d3d11->hdr.ubo_values;
|
|
|
|
D3D11UnmapBuffer(d3d11->context, d3d11->hdr.ubo, 0);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2020-08-16 03:11:00 +02:00
|
|
|
static void d3d11_set_filtering(void* data, unsigned index,
|
|
|
|
bool smooth, bool ctx_scaling)
|
2018-01-24 15:00:32 +01:00
|
|
|
{
|
2018-02-04 20:03:27 +01:00
|
|
|
unsigned i;
|
2018-01-24 15:00:32 +01:00
|
|
|
d3d11_video_t* d3d11 = (d3d11_video_t*)data;
|
|
|
|
|
2018-02-03 15:16:04 +01:00
|
|
|
for (i = 0; i < RARCH_WRAP_MAX; i++)
|
2018-02-02 17:18:41 +01:00
|
|
|
{
|
|
|
|
if (smooth)
|
|
|
|
d3d11->samplers[RARCH_FILTER_UNSPEC][i] = d3d11->samplers[RARCH_FILTER_LINEAR][i];
|
|
|
|
else
|
|
|
|
d3d11->samplers[RARCH_FILTER_UNSPEC][i] = d3d11->samplers[RARCH_FILTER_NEAREST][i];
|
|
|
|
}
|
2018-01-24 15:00:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void d3d11_gfx_set_rotation(void* data, unsigned rotation)
|
|
|
|
{
|
2018-01-31 01:08:36 +01:00
|
|
|
math_matrix_4x4 rot;
|
2018-08-16 20:49:31 +02:00
|
|
|
D3D11_MAPPED_SUBRESOURCE mapped_ubo;
|
2018-01-31 01:08:36 +01:00
|
|
|
d3d11_video_t* d3d11 = (d3d11_video_t*)data;
|
2018-01-24 15:00:32 +01:00
|
|
|
|
2018-01-25 09:48:07 +01:00
|
|
|
if (!d3d11)
|
2018-01-25 06:24:39 +01:00
|
|
|
return;
|
|
|
|
|
2018-02-03 13:29:00 +01:00
|
|
|
matrix_4x4_rotate_z(rot, rotation * (M_PI / 2.0f));
|
2018-01-25 09:48:07 +01:00
|
|
|
matrix_4x4_multiply(d3d11->mvp, rot, d3d11->ubo_values.mvp);
|
2018-01-24 15:00:32 +01:00
|
|
|
|
2018-02-03 13:29:00 +01:00
|
|
|
D3D11MapBuffer(d3d11->context, d3d11->frame.ubo, 0, D3D11_MAP_WRITE_DISCARD, 0, &mapped_ubo);
|
2018-01-24 15:00:32 +01:00
|
|
|
*(math_matrix_4x4*)mapped_ubo.pData = d3d11->mvp;
|
2018-02-03 13:29:00 +01:00
|
|
|
D3D11UnmapBuffer(d3d11->context, d3d11->frame.ubo, 0);
|
2018-01-24 15:00:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void d3d11_update_viewport(void* data, bool force_full)
|
|
|
|
{
|
|
|
|
d3d11_video_t* d3d11 = (d3d11_video_t*)data;
|
|
|
|
|
|
|
|
video_driver_update_viewport(&d3d11->vp, force_full, d3d11->keep_aspect);
|
|
|
|
|
2018-01-25 05:47:19 +01:00
|
|
|
d3d11->frame.viewport.TopLeftX = d3d11->vp.x;
|
|
|
|
d3d11->frame.viewport.TopLeftY = d3d11->vp.y;
|
|
|
|
d3d11->frame.viewport.Width = d3d11->vp.width;
|
|
|
|
d3d11->frame.viewport.Height = d3d11->vp.height;
|
2018-01-24 15:00:32 +01:00
|
|
|
d3d11->frame.viewport.MaxDepth = 0.0f;
|
|
|
|
d3d11->frame.viewport.MaxDepth = 1.0f;
|
2018-02-03 13:29:00 +01:00
|
|
|
|
|
|
|
if (d3d11->shader_preset && (d3d11->frame.output_size.x != d3d11->vp.width ||
|
2018-08-16 20:49:31 +02:00
|
|
|
d3d11->frame.output_size.y != d3d11->vp.height))
|
2018-02-03 13:29:00 +01:00
|
|
|
d3d11->resize_render_targets = true;
|
2018-02-01 12:45:35 +01:00
|
|
|
|
2018-02-01 15:07:12 +01:00
|
|
|
d3d11->frame.output_size.x = d3d11->vp.width;
|
|
|
|
d3d11->frame.output_size.y = d3d11->vp.height;
|
|
|
|
d3d11->frame.output_size.z = 1.0f / d3d11->vp.width;
|
|
|
|
d3d11->frame.output_size.w = 1.0f / d3d11->vp.height;
|
2018-01-24 15:00:32 +01:00
|
|
|
|
|
|
|
d3d11->resize_viewport = false;
|
|
|
|
}
|
|
|
|
|
2018-01-31 01:08:36 +01:00
|
|
|
static void d3d11_free_shader_preset(d3d11_video_t* d3d11)
|
|
|
|
{
|
2018-02-03 15:16:04 +01:00
|
|
|
unsigned i;
|
2018-01-31 01:08:36 +01:00
|
|
|
if (!d3d11->shader_preset)
|
|
|
|
return;
|
|
|
|
|
2018-02-03 15:16:04 +01:00
|
|
|
for (i = 0; i < d3d11->shader_preset->passes; i++)
|
2018-01-31 01:08:36 +01:00
|
|
|
{
|
2018-02-03 15:16:04 +01:00
|
|
|
unsigned j;
|
|
|
|
|
2018-01-31 01:08:36 +01:00
|
|
|
free(d3d11->shader_preset->pass[i].source.string.vertex);
|
|
|
|
free(d3d11->shader_preset->pass[i].source.string.fragment);
|
2018-02-02 19:57:45 +01:00
|
|
|
free(d3d11->pass[i].semantics.textures);
|
2022-03-05 14:39:56 +01:00
|
|
|
d3d11->shader_preset->pass[i].source.string.vertex = NULL;
|
|
|
|
d3d11->shader_preset->pass[i].source.string.fragment = NULL;
|
|
|
|
d3d11->pass[i].semantics.textures = NULL;
|
2018-01-31 01:08:36 +01:00
|
|
|
d3d11_release_shader(&d3d11->pass[i].shader);
|
|
|
|
d3d11_release_texture(&d3d11->pass[i].rt);
|
2018-02-02 19:57:45 +01:00
|
|
|
d3d11_release_texture(&d3d11->pass[i].feedback);
|
|
|
|
|
2018-02-03 15:16:04 +01:00
|
|
|
for (j = 0; j < SLANG_CBUFFER_MAX; j++)
|
2018-01-31 01:08:36 +01:00
|
|
|
{
|
|
|
|
free(d3d11->pass[i].semantics.cbuffers[j].uniforms);
|
2022-03-05 14:39:56 +01:00
|
|
|
d3d11->pass[i].semantics.cbuffers[j].uniforms = NULL;
|
2018-01-31 01:08:36 +01:00
|
|
|
Release(d3d11->pass[i].buffers[j]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
memset(d3d11->pass, 0, sizeof(d3d11->pass));
|
|
|
|
|
2018-02-03 13:29:00 +01:00
|
|
|
/* only free the history textures here */
|
2018-04-21 05:20:22 +02:00
|
|
|
for (i = 1; i <= (unsigned)d3d11->shader_preset->history_size; i++)
|
2018-02-03 13:29:00 +01:00
|
|
|
d3d11_release_texture(&d3d11->frame.texture[i]);
|
|
|
|
|
|
|
|
memset(
|
|
|
|
&d3d11->frame.texture[1], 0,
|
|
|
|
sizeof(d3d11->frame.texture[1]) * d3d11->shader_preset->history_size);
|
|
|
|
|
2018-02-03 15:16:04 +01:00
|
|
|
for (i = 0; i < d3d11->shader_preset->luts; i++)
|
2018-01-31 01:08:36 +01:00
|
|
|
d3d11_release_texture(&d3d11->luts[i]);
|
|
|
|
|
|
|
|
memset(d3d11->luts, 0, sizeof(d3d11->luts));
|
|
|
|
|
|
|
|
free(d3d11->shader_preset);
|
2018-02-03 13:29:00 +01:00
|
|
|
d3d11->shader_preset = NULL;
|
|
|
|
d3d11->init_history = false;
|
|
|
|
d3d11->resize_render_targets = false;
|
2018-01-31 01:08:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static bool d3d11_gfx_set_shader(void* data, enum rarch_shader_type type, const char* path)
|
|
|
|
{
|
2018-02-03 17:13:36 +01:00
|
|
|
#if defined(HAVE_SLANG) && defined(HAVE_SPIRV_CROSS)
|
2021-09-03 07:51:44 +02:00
|
|
|
enum d3d11_feature_level_hint
|
|
|
|
feat_level_hint = D3D11_FEATURE_LEVEL_HINT_DONTCARE;
|
2018-02-04 20:03:27 +01:00
|
|
|
unsigned i;
|
2020-11-15 13:01:55 +01:00
|
|
|
d3d11_texture_t* source = NULL;
|
|
|
|
d3d11_video_t* d3d11 = (d3d11_video_t*)data;
|
2021-09-03 07:51:44 +02:00
|
|
|
unsigned shader_model = 40;
|
2018-01-31 01:08:36 +01:00
|
|
|
|
|
|
|
if (!d3d11)
|
|
|
|
return false;
|
|
|
|
|
2021-09-03 07:51:44 +02:00
|
|
|
/* Feature Level 11.0 and up should all support Shader Model 5.0 */
|
|
|
|
switch (d3d11->supportedFeatureLevel)
|
|
|
|
{
|
|
|
|
case D3D_FEATURE_LEVEL_11_0:
|
|
|
|
shader_model = 50;
|
|
|
|
feat_level_hint = D3D11_FEATURE_LEVEL_HINT_11_0;
|
|
|
|
break;
|
|
|
|
case D3D_FEATURE_LEVEL_11_1:
|
|
|
|
shader_model = 50;
|
|
|
|
feat_level_hint = D3D11_FEATURE_LEVEL_HINT_11_1;
|
|
|
|
break;
|
|
|
|
case D3D_FEATURE_LEVEL_12_0:
|
|
|
|
shader_model = 50;
|
|
|
|
feat_level_hint = D3D11_FEATURE_LEVEL_HINT_12_0;
|
|
|
|
break;
|
|
|
|
case D3D_FEATURE_LEVEL_12_1:
|
|
|
|
shader_model = 50;
|
|
|
|
feat_level_hint = D3D11_FEATURE_LEVEL_HINT_12_1;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2018-02-03 13:29:00 +01:00
|
|
|
D3D11Flush(d3d11->context);
|
2018-01-31 01:08:36 +01:00
|
|
|
d3d11_free_shader_preset(d3d11);
|
|
|
|
|
2019-06-04 21:52:58 +02:00
|
|
|
if (string_is_empty(path))
|
2018-01-31 01:08:36 +01:00
|
|
|
return true;
|
|
|
|
|
|
|
|
if (type != RARCH_SHADER_SLANG)
|
|
|
|
{
|
2021-06-09 07:33:14 +03:00
|
|
|
RARCH_WARN("[D3D11]: Only Slang shaders are supported. Falling back to stock.\n");
|
2018-01-31 01:08:36 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-02-04 20:40:28 +01:00
|
|
|
d3d11->shader_preset = (struct video_shader*)calloc(1, sizeof(*d3d11->shader_preset));
|
2018-01-31 01:08:36 +01:00
|
|
|
|
2020-12-26 21:09:27 -05:00
|
|
|
if (!video_shader_load_preset_into_shader(path, d3d11->shader_preset))
|
2018-01-31 01:08:36 +01:00
|
|
|
goto error;
|
|
|
|
|
2018-02-04 20:03:27 +01:00
|
|
|
source = &d3d11->frame.texture[0];
|
2020-11-15 13:01:55 +01:00
|
|
|
for (i = 0; i < d3d11->shader_preset->passes; source = &d3d11->pass[i++].rt)
|
2018-01-31 01:08:36 +01:00
|
|
|
{
|
2018-02-03 15:16:04 +01:00
|
|
|
unsigned j;
|
2018-02-03 17:22:47 +01:00
|
|
|
/* clang-format off */
|
|
|
|
semantics_map_t semantics_map = {
|
|
|
|
{
|
|
|
|
/* Original */
|
|
|
|
{ &d3d11->frame.texture[0].view, 0,
|
2018-02-11 22:56:37 +01:00
|
|
|
&d3d11->frame.texture[0].size_data, 0},
|
2018-02-03 17:22:47 +01:00
|
|
|
|
|
|
|
/* Source */
|
2020-11-15 13:01:55 +01:00
|
|
|
{ &source->view, 0,
|
2018-02-11 22:56:37 +01:00
|
|
|
&source->size_data, 0},
|
2018-02-03 17:22:47 +01:00
|
|
|
|
|
|
|
/* OriginalHistory */
|
|
|
|
{ &d3d11->frame.texture[0].view, sizeof(*d3d11->frame.texture),
|
2018-02-11 22:56:37 +01:00
|
|
|
&d3d11->frame.texture[0].size_data, sizeof(*d3d11->frame.texture)},
|
2018-02-03 17:22:47 +01:00
|
|
|
|
|
|
|
/* PassOutput */
|
|
|
|
{ &d3d11->pass[0].rt.view, sizeof(*d3d11->pass),
|
2018-02-11 22:56:37 +01:00
|
|
|
&d3d11->pass[0].rt.size_data, sizeof(*d3d11->pass)},
|
2018-02-03 17:22:47 +01:00
|
|
|
|
|
|
|
/* PassFeedback */
|
|
|
|
{ &d3d11->pass[0].feedback.view, sizeof(*d3d11->pass),
|
2018-02-11 22:56:37 +01:00
|
|
|
&d3d11->pass[0].feedback.size_data, sizeof(*d3d11->pass)},
|
2018-02-03 17:22:47 +01:00
|
|
|
|
|
|
|
/* User */
|
|
|
|
{ &d3d11->luts[0].view, sizeof(*d3d11->luts),
|
2018-02-11 22:56:37 +01:00
|
|
|
&d3d11->luts[0].size_data, sizeof(*d3d11->luts)},
|
2018-02-03 17:22:47 +01:00
|
|
|
},
|
|
|
|
{
|
2019-05-29 18:09:37 +02:00
|
|
|
&d3d11->mvp, /* MVP */
|
|
|
|
&d3d11->pass[i].rt.size_data, /* OutputSize */
|
|
|
|
&d3d11->frame.output_size, /* FinalViewportSize */
|
|
|
|
&d3d11->pass[i].frame_count, /* FrameCount */
|
|
|
|
&d3d11->pass[i].frame_direction, /* FrameDirection */
|
2018-02-03 17:22:47 +01:00
|
|
|
}
|
2018-02-03 15:16:04 +01:00
|
|
|
};
|
2018-02-03 17:22:47 +01:00
|
|
|
/* clang-format on */
|
2018-01-31 01:08:36 +01:00
|
|
|
|
2018-02-03 15:16:04 +01:00
|
|
|
if (!slang_process(
|
2021-09-03 07:51:44 +02:00
|
|
|
d3d11->shader_preset, i, RARCH_SHADER_HLSL, shader_model,
|
|
|
|
&semantics_map,
|
2018-08-16 20:49:31 +02:00
|
|
|
&d3d11->pass[i].semantics))
|
2018-02-03 15:16:04 +01:00
|
|
|
goto error;
|
2018-01-31 01:08:36 +01:00
|
|
|
|
|
|
|
{
|
|
|
|
static const D3D11_INPUT_ELEMENT_DESC desc[] = {
|
|
|
|
{ "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, offsetof(d3d11_vertex_t, position),
|
2018-08-16 20:49:31 +02:00
|
|
|
D3D11_INPUT_PER_VERTEX_DATA, 0 },
|
2018-01-31 01:08:36 +01:00
|
|
|
{ "TEXCOORD", 1, DXGI_FORMAT_R32G32_FLOAT, 0, offsetof(d3d11_vertex_t, texcoord),
|
2018-08-16 20:49:31 +02:00
|
|
|
D3D11_INPUT_PER_VERTEX_DATA, 0 },
|
2018-01-31 01:08:36 +01:00
|
|
|
};
|
2018-01-31 16:12:55 +01:00
|
|
|
#ifdef DEBUG
|
|
|
|
bool save_hlsl = true;
|
|
|
|
#else
|
|
|
|
bool save_hlsl = false;
|
|
|
|
#endif
|
2018-02-02 17:18:41 +01:00
|
|
|
static const char vs_ext[] = ".vs.hlsl";
|
|
|
|
static const char ps_ext[] = ".ps.hlsl";
|
2018-08-16 13:35:04 -04:00
|
|
|
char vs_path[PATH_MAX_LENGTH] = {0};
|
|
|
|
char ps_path[PATH_MAX_LENGTH] = {0};
|
2018-02-02 17:18:41 +01:00
|
|
|
const char* slang_path = d3d11->shader_preset->pass[i].source.path;
|
|
|
|
const char* vs_src = d3d11->shader_preset->pass[i].source.string.vertex;
|
|
|
|
const char* ps_src = d3d11->shader_preset->pass[i].source.string.fragment;
|
|
|
|
|
2018-08-16 13:35:04 -04:00
|
|
|
strlcpy(vs_path, slang_path, sizeof(vs_path));
|
|
|
|
strlcpy(ps_path, slang_path, sizeof(ps_path));
|
|
|
|
strlcat(vs_path, vs_ext, sizeof(vs_path));
|
|
|
|
strlcat(ps_path, ps_ext, sizeof(ps_path));
|
2018-01-31 15:55:59 +01:00
|
|
|
|
2018-01-31 16:12:55 +01:00
|
|
|
if (!d3d11_init_shader(
|
2018-08-16 20:49:31 +02:00
|
|
|
d3d11->device, vs_src, 0, vs_path, "main", NULL, NULL, desc, countof(desc),
|
2021-09-03 07:51:44 +02:00
|
|
|
&d3d11->pass[i].shader,
|
|
|
|
feat_level_hint
|
|
|
|
))
|
2018-01-31 16:12:55 +01:00
|
|
|
save_hlsl = true;
|
2018-01-31 15:55:59 +01:00
|
|
|
|
2018-01-31 16:12:55 +01:00
|
|
|
if (!d3d11_init_shader(
|
2018-08-16 20:49:31 +02:00
|
|
|
d3d11->device, ps_src, 0, ps_path, NULL, "main", NULL, NULL, 0,
|
2021-09-03 07:51:44 +02:00
|
|
|
&d3d11->pass[i].shader,
|
|
|
|
feat_level_hint
|
|
|
|
))
|
2018-01-31 16:12:55 +01:00
|
|
|
save_hlsl = true;
|
2018-01-31 15:55:59 +01:00
|
|
|
|
2018-01-31 16:12:55 +01:00
|
|
|
if (save_hlsl)
|
2018-01-31 15:55:59 +01:00
|
|
|
{
|
2018-02-02 17:18:41 +01:00
|
|
|
FILE* fp = fopen(vs_path, "w");
|
2018-01-31 15:55:59 +01:00
|
|
|
fwrite(vs_src, 1, strlen(vs_src), fp);
|
|
|
|
fclose(fp);
|
2018-01-31 01:08:36 +01:00
|
|
|
|
2018-02-02 17:18:41 +01:00
|
|
|
fp = fopen(ps_path, "w");
|
2018-01-31 15:55:59 +01:00
|
|
|
fwrite(ps_src, 1, strlen(ps_src), fp);
|
|
|
|
fclose(fp);
|
|
|
|
}
|
2018-01-31 01:08:36 +01:00
|
|
|
|
2018-01-31 15:55:59 +01:00
|
|
|
free(d3d11->shader_preset->pass[i].source.string.vertex);
|
2018-01-31 01:08:36 +01:00
|
|
|
free(d3d11->shader_preset->pass[i].source.string.fragment);
|
2018-01-31 15:55:59 +01:00
|
|
|
|
2018-01-31 16:12:55 +01:00
|
|
|
d3d11->shader_preset->pass[i].source.string.vertex = NULL;
|
2018-01-31 01:08:36 +01:00
|
|
|
d3d11->shader_preset->pass[i].source.string.fragment = NULL;
|
2018-01-31 15:55:59 +01:00
|
|
|
|
|
|
|
if (!d3d11->pass[i].shader.vs || !d3d11->pass[i].shader.ps)
|
|
|
|
goto error;
|
2018-01-31 01:08:36 +01:00
|
|
|
}
|
|
|
|
|
2018-02-03 15:16:04 +01:00
|
|
|
for (j = 0; j < SLANG_CBUFFER_MAX; j++)
|
2018-01-31 01:08:36 +01:00
|
|
|
{
|
2018-02-04 22:12:53 +01:00
|
|
|
D3D11_BUFFER_DESC desc;
|
|
|
|
desc.ByteWidth = d3d11->pass[i].semantics.cbuffers[j].size;
|
|
|
|
desc.Usage = D3D11_USAGE_DYNAMIC;
|
|
|
|
desc.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
|
|
|
|
desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
|
|
|
|
desc.MiscFlags = 0;
|
|
|
|
desc.StructureByteStride = 0;
|
2018-01-31 01:08:36 +01:00
|
|
|
|
|
|
|
if (!desc.ByteWidth)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
D3D11CreateBuffer(d3d11->device, &desc, NULL, &d3d11->pass[i].buffers[j]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-22 01:17:17 +00:00
|
|
|
if (d3d11->hdr.enable)
|
|
|
|
{
|
|
|
|
if(d3d11->shader_preset && d3d11->shader_preset->passes && (d3d11->pass[d3d11->shader_preset->passes - 1].semantics.format == SLANG_FORMAT_A2B10G10R10_UNORM_PACK32))
|
|
|
|
{
|
|
|
|
/* If the last shader pass uses a RGB10A2 back buffer and hdr has been enabled assume we want to skip the inverse tonemapper and hdr10 conversion */
|
|
|
|
d3d11_set_hdr_inverse_tonemap(d3d11, false);
|
|
|
|
d3d11_set_hdr10(d3d11, false);
|
|
|
|
d3d11->resize_chain = true;
|
|
|
|
}
|
|
|
|
else if(d3d11->shader_preset && d3d11->shader_preset->passes && (d3d11->pass[d3d11->shader_preset->passes - 1].semantics.format == SLANG_FORMAT_R16G16B16A16_SFLOAT))
|
|
|
|
{
|
|
|
|
/* If the last shader pass uses a RGBA16 back buffer and hdr has been enabled assume we want to skip the inverse tonemapper */
|
|
|
|
d3d11_set_hdr_inverse_tonemap(d3d11, false);
|
|
|
|
d3d11_set_hdr10(d3d11, true);
|
|
|
|
d3d11->resize_chain = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
d3d11_set_hdr_inverse_tonemap(d3d11, true);
|
|
|
|
d3d11_set_hdr10(d3d11, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-03 15:16:04 +01:00
|
|
|
for (i = 0; i < d3d11->shader_preset->luts; i++)
|
2018-01-31 01:08:36 +01:00
|
|
|
{
|
|
|
|
struct texture_image image = { 0 };
|
2018-02-01 11:21:51 +01:00
|
|
|
image.supports_rgba = true;
|
2018-01-31 01:08:36 +01:00
|
|
|
|
|
|
|
if (!image_texture_load(&image, d3d11->shader_preset->lut[i].path))
|
|
|
|
goto error;
|
2018-02-03 13:29:00 +01:00
|
|
|
|
2018-01-31 01:08:36 +01:00
|
|
|
d3d11->luts[i].desc.Width = image.width;
|
|
|
|
d3d11->luts[i].desc.Height = image.height;
|
2018-02-01 11:21:51 +01:00
|
|
|
d3d11->luts[i].desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
|
2018-02-02 17:18:41 +01:00
|
|
|
|
2018-02-02 19:57:45 +01:00
|
|
|
if (d3d11->shader_preset->lut[i].mipmap)
|
2018-02-02 17:18:41 +01:00
|
|
|
d3d11->luts[i].desc.MiscFlags = D3D11_RESOURCE_MISC_GENERATE_MIPS;
|
|
|
|
|
2018-01-31 01:08:36 +01:00
|
|
|
d3d11_init_texture(d3d11->device, &d3d11->luts[i]);
|
2018-02-02 17:18:41 +01:00
|
|
|
|
2018-01-31 01:08:36 +01:00
|
|
|
d3d11_update_texture(
|
2018-02-03 13:29:00 +01:00
|
|
|
d3d11->context, image.width, image.height, 0, DXGI_FORMAT_R8G8B8A8_UNORM, image.pixels,
|
2018-01-31 01:08:36 +01:00
|
|
|
&d3d11->luts[i]);
|
2018-02-02 17:18:41 +01:00
|
|
|
|
2018-01-31 01:08:36 +01:00
|
|
|
image_texture_free(&image);
|
|
|
|
}
|
|
|
|
|
2018-02-03 13:29:00 +01:00
|
|
|
d3d11->resize_render_targets = true;
|
|
|
|
d3d11->init_history = true;
|
|
|
|
|
2018-01-31 01:08:36 +01:00
|
|
|
return true;
|
|
|
|
|
|
|
|
error:
|
|
|
|
d3d11_free_shader_preset(d3d11);
|
2018-02-03 17:01:47 +01:00
|
|
|
#endif
|
2018-01-31 01:08:36 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-01-24 20:51:19 +01:00
|
|
|
static void d3d11_gfx_free(void* data)
|
|
|
|
{
|
2018-02-04 20:03:27 +01:00
|
|
|
unsigned i;
|
2018-01-24 20:51:19 +01:00
|
|
|
d3d11_video_t* d3d11 = (d3d11_video_t*)data;
|
|
|
|
|
|
|
|
if (!d3d11)
|
|
|
|
return;
|
|
|
|
|
2018-02-12 01:19:43 +01:00
|
|
|
#ifdef HAVE_OVERLAY
|
|
|
|
d3d11_free_overlays(d3d11);
|
|
|
|
#endif
|
|
|
|
|
2018-01-31 01:08:36 +01:00
|
|
|
d3d11_free_shader_preset(d3d11);
|
|
|
|
|
2018-02-03 13:29:00 +01:00
|
|
|
d3d11_release_texture(&d3d11->frame.texture[0]);
|
2018-01-24 20:51:19 +01:00
|
|
|
Release(d3d11->frame.ubo);
|
|
|
|
Release(d3d11->frame.vbo);
|
|
|
|
|
2018-01-31 01:08:36 +01:00
|
|
|
d3d11_release_texture(&d3d11->menu.texture);
|
2018-01-24 20:51:19 +01:00
|
|
|
Release(d3d11->menu.vbo);
|
|
|
|
|
2021-09-03 06:15:25 +02:00
|
|
|
#ifdef HAVE_DXGI_HDR
|
|
|
|
Release(d3d11->hdr.ubo);
|
|
|
|
#endif
|
|
|
|
|
2018-01-31 01:08:36 +01:00
|
|
|
d3d11_release_shader(&d3d11->sprites.shader);
|
|
|
|
d3d11_release_shader(&d3d11->sprites.shader_font);
|
2018-01-24 20:51:19 +01:00
|
|
|
Release(d3d11->sprites.vbo);
|
2018-01-25 15:48:53 +01:00
|
|
|
|
2018-02-06 18:00:11 +01:00
|
|
|
for (i = 0; i < GFX_MAX_SHADERS; i++)
|
|
|
|
d3d11_release_shader(&d3d11->shaders[i]);
|
2018-01-24 20:51:19 +01:00
|
|
|
|
2018-01-25 09:48:07 +01:00
|
|
|
Release(d3d11->menu_pipeline_vbo);
|
2018-01-25 15:48:53 +01:00
|
|
|
Release(d3d11->blend_pipeline);
|
2018-01-25 09:48:07 +01:00
|
|
|
|
2018-01-24 20:51:19 +01:00
|
|
|
Release(d3d11->ubo);
|
2018-01-25 15:48:53 +01:00
|
|
|
|
2018-01-24 20:51:19 +01:00
|
|
|
Release(d3d11->blend_enable);
|
|
|
|
Release(d3d11->blend_disable);
|
2018-01-25 15:48:53 +01:00
|
|
|
|
2018-02-03 15:16:04 +01:00
|
|
|
for (i = 0; i < RARCH_WRAP_MAX; i++)
|
2018-02-02 17:18:41 +01:00
|
|
|
{
|
|
|
|
Release(d3d11->samplers[RARCH_FILTER_LINEAR][i]);
|
|
|
|
Release(d3d11->samplers[RARCH_FILTER_NEAREST][i]);
|
|
|
|
}
|
2018-01-25 15:48:53 +01:00
|
|
|
|
2021-09-03 06:15:25 +02:00
|
|
|
#ifdef HAVE_DXGI_HDR
|
|
|
|
d3d11_release_texture(&d3d11->back_buffer);
|
|
|
|
#endif
|
|
|
|
|
2020-11-15 13:01:55 +01:00
|
|
|
Release(d3d11->scissor_enabled);
|
|
|
|
Release(d3d11->scissor_disabled);
|
2018-01-24 20:51:19 +01:00
|
|
|
Release(d3d11->swapChain);
|
2018-01-25 00:20:06 +01:00
|
|
|
|
|
|
|
font_driver_free_osd();
|
|
|
|
|
2018-08-16 20:49:31 +02:00
|
|
|
if (video_driver_is_video_cache_context())
|
|
|
|
{
|
2020-12-15 22:56:06 +01:00
|
|
|
cached_device_d3d11 = d3d11->device;
|
|
|
|
cached_context_d3d11 = d3d11->context;
|
2018-08-16 20:49:31 +02:00
|
|
|
cached_supportedFeatureLevel = d3d11->supportedFeatureLevel;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Release(d3d11->context);
|
|
|
|
Release(d3d11->device);
|
|
|
|
}
|
2018-01-24 20:51:19 +01:00
|
|
|
|
2019-06-18 16:33:37 -04:00
|
|
|
for (i = 0; i < D3D11_MAX_GPU_COUNT; i++)
|
|
|
|
{
|
2020-08-03 12:36:51 +02:00
|
|
|
if (d3d11->adapters[i])
|
2019-06-18 16:33:37 -04:00
|
|
|
{
|
2020-08-03 12:36:51 +02:00
|
|
|
Release(d3d11->adapters[i]);
|
|
|
|
d3d11->adapters[i] = NULL;
|
2019-06-18 16:33:37 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-03 06:15:25 +02:00
|
|
|
#ifdef HAVE_DXGI_HDR
|
|
|
|
video_driver_unset_hdr_support();
|
|
|
|
#endif
|
|
|
|
|
2018-12-28 12:41:38 +01:00
|
|
|
#ifdef HAVE_MONITOR
|
2018-01-24 20:51:19 +01:00
|
|
|
win32_monitor_from_window();
|
2018-12-28 12:41:38 +01:00
|
|
|
#endif
|
|
|
|
#ifdef HAVE_WINDOW
|
2018-01-24 20:51:19 +01:00
|
|
|
win32_destroy_window();
|
2018-12-28 12:41:38 +01:00
|
|
|
#endif
|
2018-01-24 20:51:19 +01:00
|
|
|
free(d3d11);
|
|
|
|
}
|
|
|
|
|
2020-12-15 22:56:06 +01:00
|
|
|
static bool d3d11_init_swapchain(d3d11_video_t* d3d11,
|
|
|
|
int width, int height,
|
|
|
|
D3D11Device *cached_device,
|
|
|
|
D3D11DeviceContext *cached_context,
|
|
|
|
void *corewindow)
|
2020-12-15 08:19:04 +01:00
|
|
|
{
|
2021-09-03 06:15:25 +02:00
|
|
|
HWND hwnd;
|
2020-12-15 22:56:06 +01:00
|
|
|
#ifdef __WINRT__
|
|
|
|
IDXGIFactory2* dxgiFactory = NULL;
|
|
|
|
#else
|
2021-06-22 00:41:56 +02:00
|
|
|
IDXGIFactory* dxgiFactory = NULL;
|
2021-06-16 23:19:27 +10:00
|
|
|
IDXGIFactory5* dxgiFactory5 = NULL;
|
2020-12-15 22:56:06 +01:00
|
|
|
#endif
|
2020-12-15 08:19:04 +01:00
|
|
|
IDXGIDevice* dxgiDevice = NULL;
|
|
|
|
IDXGIAdapter* adapter = NULL;
|
|
|
|
UINT flags = 0;
|
|
|
|
D3D_FEATURE_LEVEL
|
|
|
|
requested_feature_levels[] =
|
|
|
|
{
|
|
|
|
D3D_FEATURE_LEVEL_11_0,
|
|
|
|
D3D_FEATURE_LEVEL_10_1,
|
|
|
|
D3D_FEATURE_LEVEL_10_0
|
|
|
|
};
|
|
|
|
#ifdef __WINRT__
|
|
|
|
/* UWP requires the use of newer version of the factory which requires newer version of this struct */
|
|
|
|
DXGI_SWAP_CHAIN_DESC1 desc = {{0}};
|
|
|
|
#else
|
|
|
|
DXGI_SWAP_CHAIN_DESC desc = {{0}};
|
|
|
|
#endif
|
|
|
|
UINT number_feature_levels = ARRAY_SIZE(requested_feature_levels);
|
|
|
|
|
2021-09-03 06:15:25 +02:00
|
|
|
#ifdef HAVE_DXGI_HDR
|
|
|
|
DXGI_COLOR_SPACE_TYPE color_space;
|
|
|
|
|
|
|
|
d3d11->chain_formats[DXGI_SWAPCHAIN_BIT_DEPTH_8] = DXGI_FORMAT_R8G8B8A8_UNORM;
|
|
|
|
d3d11->chain_formats[DXGI_SWAPCHAIN_BIT_DEPTH_10] = DXGI_FORMAT_R10G10B10A2_UNORM;
|
|
|
|
d3d11->chain_formats[DXGI_SWAPCHAIN_BIT_DEPTH_16] = DXGI_FORMAT_R16G16B16A16_UNORM;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
hwnd = (HWND)corewindow;
|
|
|
|
|
|
|
|
#ifdef HAVE_DXGI_HDR
|
|
|
|
if (!(d3d11->hdr.support =
|
|
|
|
dxgi_check_display_hdr_support(d3d11->factory, hwnd)))
|
|
|
|
d3d11->hdr.enable = false;
|
|
|
|
|
|
|
|
d3d11->chain_bit_depth = d3d11->hdr.enable
|
|
|
|
? DXGI_SWAPCHAIN_BIT_DEPTH_10
|
|
|
|
: DXGI_SWAPCHAIN_BIT_DEPTH_8;
|
|
|
|
#endif
|
|
|
|
|
2020-12-15 08:19:04 +01:00
|
|
|
#ifdef __WINRT__
|
2020-12-15 22:56:06 +01:00
|
|
|
/* Flip model forces us to do double-buffering */
|
|
|
|
desc.BufferCount = 2;
|
|
|
|
|
|
|
|
desc.Width = width;
|
|
|
|
desc.Height = height;
|
2021-09-03 06:15:25 +02:00
|
|
|
#ifdef HAVE_DXGI_HDR
|
|
|
|
if (d3d11->hdr.support)
|
|
|
|
desc.Format = d3d11->chain_formats[
|
|
|
|
d3d11->chain_bit_depth];
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
|
2020-12-15 08:19:04 +01:00
|
|
|
#else
|
2020-12-17 14:39:58 +01:00
|
|
|
desc.BufferCount = 2;
|
2020-12-15 22:56:06 +01:00
|
|
|
|
|
|
|
desc.BufferDesc.Width = width;
|
|
|
|
desc.BufferDesc.Height = height;
|
2021-09-03 06:15:25 +02:00
|
|
|
#ifdef HAVE_DXGI_HDR
|
|
|
|
if (d3d11->hdr.support)
|
|
|
|
desc.BufferDesc.Format = d3d11->chain_formats[
|
|
|
|
d3d11->chain_bit_depth];
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
desc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
|
2020-12-15 08:19:04 +01:00
|
|
|
desc.BufferDesc.RefreshRate.Numerator = 60;
|
|
|
|
desc.BufferDesc.RefreshRate.Denominator = 1;
|
|
|
|
#endif
|
|
|
|
desc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
|
|
|
|
#ifdef HAVE_WINDOW
|
2021-03-22 15:20:51 +01:00
|
|
|
desc.OutputWindow = (HWND)corewindow;
|
2020-12-15 08:19:04 +01:00
|
|
|
#endif
|
|
|
|
desc.SampleDesc.Count = 1;
|
|
|
|
desc.SampleDesc.Quality = 0;
|
|
|
|
#if 0
|
|
|
|
desc.Scaling = DXGI_SCALING_STRETCH;
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_WINDOW
|
|
|
|
desc.Windowed = TRUE;
|
|
|
|
#endif
|
2021-06-22 00:41:56 +02:00
|
|
|
|
2020-12-15 08:19:04 +01:00
|
|
|
#ifdef DEBUG
|
|
|
|
flags |= D3D11_CREATE_DEVICE_DEBUG;
|
|
|
|
#endif
|
|
|
|
|
2021-06-22 00:41:56 +02:00
|
|
|
|
2020-12-15 22:56:06 +01:00
|
|
|
if(*cached_device && *cached_context)
|
2020-12-15 08:19:04 +01:00
|
|
|
{
|
2020-12-15 22:56:06 +01:00
|
|
|
d3d11->device = *cached_device;
|
|
|
|
d3d11->context = *cached_context;
|
2020-12-15 08:19:04 +01:00
|
|
|
d3d11->supportedFeatureLevel = cached_supportedFeatureLevel;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (FAILED(D3D11CreateDevice(
|
2020-12-15 22:56:06 +01:00
|
|
|
(IDXGIAdapter*)d3d11->adapter,
|
|
|
|
D3D_DRIVER_TYPE_HARDWARE, NULL, flags,
|
2020-12-15 08:19:04 +01:00
|
|
|
requested_feature_levels, number_feature_levels,
|
|
|
|
D3D11_SDK_VERSION, &d3d11->device,
|
|
|
|
&d3d11->supportedFeatureLevel, &d3d11->context)))
|
|
|
|
return false;
|
2021-09-03 07:15:53 +02:00
|
|
|
switch (d3d11->supportedFeatureLevel)
|
|
|
|
{
|
|
|
|
case D3D_FEATURE_LEVEL_9_1:
|
|
|
|
RARCH_LOG("[D3D11] Device created (Feature Level: 9.1)\n");
|
|
|
|
break;
|
|
|
|
case D3D_FEATURE_LEVEL_9_2:
|
|
|
|
RARCH_LOG("[D3D11] Device created (Feature Level: 9.2)\n");
|
|
|
|
break;
|
|
|
|
case D3D_FEATURE_LEVEL_9_3:
|
|
|
|
RARCH_LOG("[D3D11] Device created (Feature Level: 9.3)\n");
|
|
|
|
break;
|
|
|
|
case D3D_FEATURE_LEVEL_10_0:
|
|
|
|
RARCH_LOG("[D3D11] Device created (Feature Level: 10.0)\n");
|
|
|
|
break;
|
|
|
|
case D3D_FEATURE_LEVEL_10_1:
|
|
|
|
RARCH_LOG("[D3D11] Device created (Feature Level: 10.1)\n");
|
|
|
|
break;
|
|
|
|
case D3D_FEATURE_LEVEL_11_0:
|
|
|
|
RARCH_LOG("[D3D11] Device created (Feature Level: 11.0)\n");
|
|
|
|
break;
|
|
|
|
case D3D_FEATURE_LEVEL_11_1:
|
|
|
|
RARCH_LOG("[D3D11] Device created (Feature Level: 11.1)\n");
|
|
|
|
break;
|
|
|
|
case D3D_FEATURE_LEVEL_12_0:
|
|
|
|
RARCH_LOG("[D3D11] Device created (Feature Level: 12.0)\n");
|
|
|
|
break;
|
|
|
|
case D3D_FEATURE_LEVEL_12_1:
|
|
|
|
RARCH_LOG("[D3D11] Device created (Feature Level: 12.1)\n");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
RARCH_LOG("[D3D11] Device created (Feature Level: N/A)\n");
|
|
|
|
break;
|
|
|
|
}
|
2020-12-15 08:19:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
d3d11->device->lpVtbl->QueryInterface(
|
|
|
|
d3d11->device, uuidof(IDXGIDevice), (void**)&dxgiDevice);
|
|
|
|
dxgiDevice->lpVtbl->GetAdapter(dxgiDevice, &adapter);
|
2021-06-22 00:41:56 +02:00
|
|
|
|
2020-12-15 08:19:04 +01:00
|
|
|
#ifdef __WINRT__
|
2021-06-22 00:41:56 +02:00
|
|
|
#if defined(WINAPI_FAMILY) && (WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP)
|
|
|
|
/* On phone, no swap effects are supported. */
|
|
|
|
/* TODO/FIXME - need to verify if this is needed and if
|
|
|
|
* flip model cannot be used here */
|
|
|
|
desc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
|
|
|
|
#else
|
|
|
|
d3d11->has_flip_model = true;
|
|
|
|
d3d11->has_allow_tearing = true;
|
|
|
|
desc.Flags = DXGI_SWAP_CHAIN_FLAG_ALLOW_TEARING;
|
|
|
|
desc.SwapEffect = DXGI_SWAP_EFFECT_FLIP_DISCARD;
|
|
|
|
#endif
|
|
|
|
|
2020-12-15 08:19:04 +01:00
|
|
|
adapter->lpVtbl->GetParent(
|
|
|
|
adapter, uuidof(IDXGIFactory2), (void**)&dxgiFactory);
|
|
|
|
if (FAILED(dxgiFactory->lpVtbl->CreateSwapChainForCoreWindow(
|
2020-12-15 22:56:06 +01:00
|
|
|
dxgiFactory, (IUnknown*)d3d11->device, corewindow,
|
2020-12-15 08:19:04 +01:00
|
|
|
&desc, NULL, (IDXGISwapChain1**)&d3d11->swapChain)))
|
|
|
|
return false;
|
|
|
|
#else
|
2021-06-22 00:41:56 +02:00
|
|
|
desc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
|
|
|
|
|
2020-12-15 08:19:04 +01:00
|
|
|
adapter->lpVtbl->GetParent(
|
|
|
|
adapter, uuidof(IDXGIFactory1), (void**)&dxgiFactory);
|
2021-06-16 23:19:27 +10:00
|
|
|
|
|
|
|
/* Check for ALLOW_TEARING support before trying to use it.
|
|
|
|
* Also don't use the flip model if it's not supported, because then we can't uncap our
|
|
|
|
* present rate. */
|
|
|
|
if (SUCCEEDED(dxgiFactory->lpVtbl->QueryInterface(
|
2021-06-16 16:07:38 +02:00
|
|
|
dxgiFactory, &libretro_IID_IDXGIFactory5, (void**)&dxgiFactory5)))
|
2021-06-16 23:19:27 +10:00
|
|
|
{
|
|
|
|
BOOL allow_tearing_supported = FALSE;
|
|
|
|
if (SUCCEEDED(dxgiFactory5->lpVtbl->CheckFeatureSupport(
|
|
|
|
dxgiFactory5, DXGI_FEATURE_PRESENT_ALLOW_TEARING,
|
|
|
|
&allow_tearing_supported, sizeof(allow_tearing_supported))) &&
|
|
|
|
allow_tearing_supported)
|
|
|
|
{
|
|
|
|
desc.SwapEffect = DXGI_SWAP_EFFECT_FLIP_DISCARD;
|
|
|
|
desc.Flags |= DXGI_SWAP_CHAIN_FLAG_ALLOW_TEARING;
|
|
|
|
d3d11->has_flip_model = true;
|
|
|
|
d3d11->has_allow_tearing = true;
|
2021-06-22 00:41:56 +02:00
|
|
|
|
|
|
|
RARCH_LOG("[D3D11]: Flip model and tear control supported and enabled.\n");
|
2021-06-16 23:19:27 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
dxgiFactory5->lpVtbl->Release(dxgiFactory5);
|
|
|
|
}
|
|
|
|
|
2020-12-15 08:19:04 +01:00
|
|
|
if (FAILED(dxgiFactory->lpVtbl->CreateSwapChain(
|
|
|
|
dxgiFactory, (IUnknown*)d3d11->device,
|
|
|
|
&desc, (IDXGISwapChain**)&d3d11->swapChain)))
|
2020-12-17 14:39:58 +01:00
|
|
|
{
|
|
|
|
RARCH_WARN("[D3D11]: Failed to create swapchain with flip model, try non-flip model.\n");
|
|
|
|
|
|
|
|
/* Failed to create swapchain, try non-flip model */
|
2021-06-16 23:19:27 +10:00
|
|
|
desc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
|
|
|
|
desc.Flags &= ~DXGI_SWAP_CHAIN_FLAG_ALLOW_TEARING;
|
|
|
|
d3d11->has_flip_model = false;
|
|
|
|
d3d11->has_allow_tearing = false;
|
2020-12-17 14:39:58 +01:00
|
|
|
|
|
|
|
if (FAILED(dxgiFactory->lpVtbl->CreateSwapChain(
|
|
|
|
dxgiFactory, (IUnknown*)d3d11->device,
|
|
|
|
&desc, (IDXGISwapChain**)&d3d11->swapChain)))
|
|
|
|
return false;
|
|
|
|
}
|
2021-06-22 13:44:09 +10:00
|
|
|
|
|
|
|
#ifdef HAVE_WINDOW
|
|
|
|
/* Don't let DXGI mess with the full screen state, because otherwise we end up with a mismatch
|
|
|
|
* between the window size and the buffers. RetroArch only uses windowed mode (see above). */
|
|
|
|
if (FAILED(dxgiFactory->lpVtbl->MakeWindowAssociation(dxgiFactory, desc.OutputWindow,
|
|
|
|
DXGI_MWA_NO_ALT_ENTER)))
|
|
|
|
{
|
|
|
|
RARCH_ERR("[D3D11]: Failed to make disable DXGI ALT+ENTER handling.\n");
|
|
|
|
}
|
2020-12-15 08:19:04 +01:00
|
|
|
#endif
|
|
|
|
|
2021-09-03 06:15:25 +02:00
|
|
|
#endif /* __WINRT__ */
|
|
|
|
|
|
|
|
#ifdef HAVE_DXGI_HDR
|
|
|
|
/* Check display HDR support and
|
|
|
|
initialize ST.2084 support to match
|
|
|
|
the display's support. */
|
|
|
|
#if 0
|
|
|
|
d3d11->hdr.max_output_nits = 300.0f;
|
|
|
|
d3d11->hdr.min_output_nits = 0.001f;
|
|
|
|
d3d11->hdr.max_cll = 0.0f;
|
|
|
|
d3d11->hdr.max_fall = 0.0f;
|
|
|
|
#endif
|
|
|
|
color_space =
|
|
|
|
d3d11->hdr.enable
|
|
|
|
? DXGI_COLOR_SPACE_RGB_FULL_G2084_NONE_P2020
|
|
|
|
: DXGI_COLOR_SPACE_RGB_FULL_G22_NONE_P709;
|
|
|
|
|
|
|
|
dxgi_swapchain_color_space(
|
|
|
|
d3d11->swapChain,
|
|
|
|
&d3d11->chain_color_space,
|
|
|
|
color_space);
|
|
|
|
dxgi_set_hdr_metadata(
|
|
|
|
d3d11->swapChain,
|
|
|
|
d3d11->hdr.support,
|
|
|
|
d3d11->chain_bit_depth,
|
|
|
|
d3d11->chain_color_space,
|
|
|
|
d3d11->hdr.max_output_nits,
|
|
|
|
d3d11->hdr.min_output_nits,
|
|
|
|
d3d11->hdr.max_cll,
|
|
|
|
d3d11->hdr.max_fall);
|
|
|
|
|
|
|
|
memset(&d3d11->back_buffer, 0, sizeof(d3d11->back_buffer));
|
|
|
|
d3d11->back_buffer.desc.Width = width;
|
|
|
|
d3d11->back_buffer.desc.Height = height;
|
2021-12-22 01:17:17 +00:00
|
|
|
d3d11->back_buffer.desc.Format = d3d11->shader_preset && d3d11->shader_preset->passes ? glslang_format_to_dxgi(d3d11->pass[d3d11->shader_preset->passes - 1].semantics.format) : DXGI_FORMAT_R8G8B8A8_UNORM;
|
2021-09-03 06:15:25 +02:00
|
|
|
d3d11->back_buffer.desc.BindFlags = D3D11_BIND_RENDER_TARGET;
|
|
|
|
d3d11_init_texture(d3d11->device, &d3d11->back_buffer);
|
|
|
|
#endif
|
2021-06-22 13:44:09 +10:00
|
|
|
|
2020-12-15 08:19:04 +01:00
|
|
|
dxgiFactory->lpVtbl->Release(dxgiFactory);
|
|
|
|
adapter->lpVtbl->Release(adapter);
|
|
|
|
dxgiDevice->lpVtbl->Release(dxgiDevice);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-07-27 02:21:24 +02:00
|
|
|
static void *d3d11_gfx_init(const video_info_t* video,
|
|
|
|
input_driver_t** input, void** input_data)
|
2018-01-21 04:10:45 +01:00
|
|
|
{
|
2018-02-04 20:03:27 +01:00
|
|
|
unsigned i;
|
2018-12-28 12:41:38 +01:00
|
|
|
#ifdef HAVE_MONITOR
|
2018-01-31 01:08:36 +01:00
|
|
|
MONITORINFOEX current_mon;
|
|
|
|
HMONITOR hm_to_use;
|
2018-03-30 15:50:11 +02:00
|
|
|
WNDCLASSEX wndclass = { 0 };
|
2018-12-28 12:41:38 +01:00
|
|
|
#endif
|
2018-01-31 01:08:36 +01:00
|
|
|
settings_t* settings = config_get_ptr();
|
|
|
|
d3d11_video_t* d3d11 = (d3d11_video_t*)calloc(1, sizeof(*d3d11));
|
2018-01-21 04:10:45 +01:00
|
|
|
|
|
|
|
if (!d3d11)
|
|
|
|
return NULL;
|
|
|
|
|
2018-12-28 12:41:38 +01:00
|
|
|
#ifdef HAVE_WINDOW
|
2018-01-21 04:10:45 +01:00
|
|
|
win32_window_reset();
|
2018-12-30 04:51:03 +01:00
|
|
|
#endif
|
|
|
|
#ifdef HAVE_MONITOR
|
2018-01-21 04:10:45 +01:00
|
|
|
win32_monitor_init();
|
2020-08-28 02:55:39 +02:00
|
|
|
wndclass.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"))
|
|
|
|
wndclass.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"))
|
|
|
|
wndclass.lpfnWndProc = wnd_proc_d3d_winraw;
|
2020-08-28 02:21:13 +02:00
|
|
|
#endif
|
2018-12-30 04:51:03 +01:00
|
|
|
#ifdef HAVE_WINDOW
|
2018-01-21 04:10:45 +01:00
|
|
|
win32_window_init(&wndclass, true, NULL);
|
2018-12-28 12:41:38 +01:00
|
|
|
#endif
|
2018-01-21 04:10:45 +01:00
|
|
|
|
2018-01-25 00:20:06 +01:00
|
|
|
win32_monitor_info(¤t_mon, &hm_to_use, &d3d11->cur_mon_id);
|
2018-12-28 12:41:38 +01:00
|
|
|
#endif
|
2018-01-25 00:20:06 +01:00
|
|
|
|
|
|
|
d3d11->vp.full_width = video->width;
|
|
|
|
d3d11->vp.full_height = video->height;
|
|
|
|
|
2018-12-28 12:41:38 +01:00
|
|
|
#ifdef HAVE_MONITOR
|
2018-01-25 00:20:06 +01:00
|
|
|
if (!d3d11->vp.full_width)
|
|
|
|
d3d11->vp.full_width = current_mon.rcMonitor.right - current_mon.rcMonitor.left;
|
|
|
|
if (!d3d11->vp.full_height)
|
|
|
|
d3d11->vp.full_height = current_mon.rcMonitor.bottom - current_mon.rcMonitor.top;
|
2018-12-28 12:41:38 +01:00
|
|
|
#endif
|
2018-01-25 00:20:06 +01:00
|
|
|
|
|
|
|
if (!win32_set_video_mode(d3d11, d3d11->vp.full_width, d3d11->vp.full_height, video->fullscreen))
|
2018-01-21 04:10:45 +01:00
|
|
|
{
|
|
|
|
RARCH_ERR("[D3D11]: win32_set_video_mode failed.\n");
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
2018-12-28 12:41:38 +01:00
|
|
|
d3d_input_driver(settings->arrays.input_driver, settings->arrays.input_joypad_driver, input, input_data);
|
2018-01-21 04:10:45 +01:00
|
|
|
|
2021-09-03 06:15:25 +02:00
|
|
|
#ifdef __WINRT__
|
|
|
|
DXGICreateFactory2(&d3d11->factory);
|
|
|
|
#else
|
|
|
|
DXGICreateFactory(&d3d11->factory);
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_DXGI_HDR
|
|
|
|
d3d11->hdr.enable = settings->bools.video_hdr_enable;
|
|
|
|
d3d11->hdr.max_output_nits = settings->floats.video_hdr_max_nits;
|
|
|
|
d3d11->hdr.min_output_nits = 0.001f;
|
|
|
|
d3d11->hdr.max_cll = 0.0f;
|
|
|
|
d3d11->hdr.max_fall = 0.0f;
|
|
|
|
#endif
|
|
|
|
|
2020-12-15 22:56:06 +01:00
|
|
|
#ifdef __WINRT__
|
|
|
|
if (!d3d11_init_swapchain(d3d11,
|
|
|
|
d3d11->vp.full_width,
|
|
|
|
d3d11->vp.full_height,
|
|
|
|
&cached_device_d3d11,
|
|
|
|
&cached_context_d3d11,
|
|
|
|
uwp_get_corewindow()
|
|
|
|
))
|
|
|
|
goto error;
|
|
|
|
#else
|
|
|
|
if (!d3d11_init_swapchain(d3d11,
|
|
|
|
d3d11->vp.full_width,
|
|
|
|
d3d11->vp.full_height,
|
|
|
|
&cached_device_d3d11,
|
|
|
|
&cached_context_d3d11,
|
|
|
|
main_window.hwnd
|
|
|
|
))
|
2020-12-15 08:19:04 +01:00
|
|
|
goto error;
|
2020-12-15 22:56:06 +01:00
|
|
|
#endif
|
2018-01-21 04:10:45 +01:00
|
|
|
|
2020-01-31 03:47:50 +01:00
|
|
|
video_driver_set_size(d3d11->vp.full_width, d3d11->vp.full_height);
|
2018-01-25 00:20:06 +01:00
|
|
|
d3d11->viewport.Width = d3d11->vp.full_width;
|
|
|
|
d3d11->viewport.Height = d3d11->vp.full_height;
|
2020-11-15 13:01:55 +01:00
|
|
|
d3d11->scissor.right = d3d11->vp.full_width;
|
|
|
|
d3d11->scissor.bottom = d3d11->vp.full_height;
|
2018-01-24 15:00:32 +01:00
|
|
|
d3d11->resize_viewport = true;
|
2019-07-23 01:33:43 +07:00
|
|
|
d3d11->keep_aspect = video->force_aspect;
|
2018-01-24 20:51:19 +01:00
|
|
|
d3d11->vsync = video->vsync;
|
2019-02-03 15:49:35 -08:00
|
|
|
d3d11->format = video->rgb32 ?
|
2018-04-17 21:29:02 +02:00
|
|
|
DXGI_FORMAT_B8G8R8X8_UNORM : DXGI_FORMAT_B5G6R5_UNORM;
|
2018-01-22 07:35:36 +01:00
|
|
|
|
2018-02-03 13:29:00 +01:00
|
|
|
d3d11->frame.texture[0].desc.Format = d3d11->format;
|
|
|
|
d3d11->frame.texture[0].desc.Usage = D3D11_USAGE_DEFAULT;
|
2018-02-12 03:25:37 +01:00
|
|
|
d3d11->frame.texture[0].desc.Width = 4;
|
|
|
|
d3d11->frame.texture[0].desc.Height = 4;
|
2018-04-17 21:29:02 +02:00
|
|
|
|
2018-02-12 03:25:37 +01:00
|
|
|
d3d11_init_texture(d3d11->device, &d3d11->frame.texture[0]);
|
2018-01-22 07:35:36 +01:00
|
|
|
|
2018-01-25 09:48:07 +01:00
|
|
|
d3d11->menu.texture.desc.Usage = D3D11_USAGE_DEFAULT;
|
|
|
|
|
|
|
|
matrix_4x4_ortho(d3d11->ubo_values.mvp, 0.0f, 1.0f, 0.0f, 1.0f, -1.0f, 1.0f);
|
2018-01-21 04:10:45 +01:00
|
|
|
|
2018-01-25 09:48:07 +01:00
|
|
|
d3d11->ubo_values.OutputSize.width = d3d11->viewport.Width;
|
|
|
|
d3d11->ubo_values.OutputSize.height = d3d11->viewport.Height;
|
2018-01-24 15:00:32 +01:00
|
|
|
|
|
|
|
{
|
2018-02-04 21:50:05 +01:00
|
|
|
D3D11_SUBRESOURCE_DATA ubo_data;
|
2018-02-12 01:19:43 +01:00
|
|
|
D3D11_BUFFER_DESC desc;
|
|
|
|
desc.ByteWidth = sizeof(d3d11->ubo_values);
|
|
|
|
desc.Usage = D3D11_USAGE_DYNAMIC;
|
|
|
|
desc.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
|
|
|
|
desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
|
|
|
|
desc.MiscFlags = 0;
|
|
|
|
desc.StructureByteStride = 0;
|
2018-02-04 22:12:53 +01:00
|
|
|
|
|
|
|
ubo_data.pSysMem = &d3d11->ubo_values.mvp;
|
|
|
|
ubo_data.SysMemPitch = 0;
|
|
|
|
ubo_data.SysMemSlicePitch = 0;
|
2018-02-04 21:50:05 +01:00
|
|
|
|
2018-01-24 15:00:32 +01:00
|
|
|
D3D11CreateBuffer(d3d11->device, &desc, &ubo_data, &d3d11->ubo);
|
|
|
|
D3D11CreateBuffer(d3d11->device, &desc, NULL, &d3d11->frame.ubo);
|
|
|
|
}
|
2018-01-31 01:08:36 +01:00
|
|
|
|
2018-01-24 15:00:32 +01:00
|
|
|
d3d11_gfx_set_rotation(d3d11, 0);
|
|
|
|
|
2021-09-03 06:15:25 +02:00
|
|
|
#ifdef HAVE_DXGI_HDR
|
|
|
|
if (d3d11->hdr.enable)
|
|
|
|
{
|
|
|
|
D3D11_BUFFER_DESC desc;
|
|
|
|
D3D11_SUBRESOURCE_DATA ubo_data;
|
|
|
|
matrix_4x4_ortho(d3d11->mvp_no_rot, 0.0f, 1.0f, 0.0f, 1.0f, -1.0f, 1.0f);
|
|
|
|
|
2021-09-13 15:54:50 +01:00
|
|
|
d3d11->hdr.ubo_values.mvp =
|
2021-09-03 06:15:25 +02:00
|
|
|
d3d11->mvp_no_rot;
|
2021-09-13 15:54:50 +01:00
|
|
|
d3d11->hdr.ubo_values.max_nits =
|
2021-09-03 06:15:25 +02:00
|
|
|
settings->floats.video_hdr_max_nits;
|
2021-09-13 15:54:50 +01:00
|
|
|
d3d11->hdr.ubo_values.paper_white_nits =
|
2021-09-03 06:15:25 +02:00
|
|
|
settings->floats.video_hdr_paper_white_nits;
|
2021-09-13 15:54:50 +01:00
|
|
|
d3d11->hdr.ubo_values.contrast =
|
|
|
|
VIDEO_HDR_MAX_CONTRAST - settings->floats.video_hdr_display_contrast;
|
|
|
|
d3d11->hdr.ubo_values.expand_gamut =
|
2021-09-03 06:15:25 +02:00
|
|
|
settings->bools.video_hdr_expand_gamut;
|
2021-09-13 15:54:50 +01:00
|
|
|
d3d11->hdr.ubo_values.inverse_tonemap = 1.0f; /* Use this to turn on/off the inverse tonemap */
|
2021-12-22 01:17:17 +00:00
|
|
|
d3d11->hdr.ubo_values.hdr10 = 1.0f; /* Use this to turn on/off the hdr10 */
|
2021-09-03 06:15:25 +02:00
|
|
|
|
|
|
|
desc.ByteWidth = sizeof(dxgi_hdr_uniform_t);
|
|
|
|
desc.Usage = D3D11_USAGE_DYNAMIC;
|
|
|
|
desc.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
|
|
|
|
desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
|
|
|
|
desc.MiscFlags = 0;
|
|
|
|
desc.StructureByteStride = 0;
|
|
|
|
|
|
|
|
ubo_data.pSysMem = &d3d11->hdr.ubo_values.mvp;
|
|
|
|
ubo_data.SysMemPitch = 0;
|
|
|
|
ubo_data.SysMemSlicePitch = 0;
|
|
|
|
|
|
|
|
D3D11CreateBuffer(d3d11->device, &desc, &ubo_data, &d3d11->hdr.ubo);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2018-01-21 04:10:45 +01:00
|
|
|
{
|
2018-02-04 20:03:27 +01:00
|
|
|
D3D11_SAMPLER_DESC desc = { D3D11_FILTER_MIN_MAG_MIP_POINT };
|
|
|
|
desc.MaxAnisotropy = 1;
|
|
|
|
desc.ComparisonFunc = D3D11_COMPARISON_NEVER;
|
|
|
|
desc.MinLOD = -D3D11_FLOAT32_MAX;
|
|
|
|
desc.MaxLOD = D3D11_FLOAT32_MAX;
|
|
|
|
|
2018-02-02 17:18:41 +01:00
|
|
|
/* Initialize samplers */
|
2018-02-03 15:16:04 +01:00
|
|
|
for (i = 0; i < RARCH_WRAP_MAX; i++)
|
2018-02-02 17:18:41 +01:00
|
|
|
{
|
|
|
|
switch (i)
|
|
|
|
{
|
|
|
|
case RARCH_WRAP_BORDER:
|
|
|
|
desc.AddressU = D3D11_TEXTURE_ADDRESS_BORDER;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case RARCH_WRAP_EDGE:
|
|
|
|
desc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
|
|
|
|
break;
|
2018-01-21 23:46:50 +01:00
|
|
|
|
2018-02-02 17:18:41 +01:00
|
|
|
case RARCH_WRAP_REPEAT:
|
|
|
|
desc.AddressU = D3D11_TEXTURE_ADDRESS_WRAP;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case RARCH_WRAP_MIRRORED_REPEAT:
|
|
|
|
desc.AddressU = D3D11_TEXTURE_ADDRESS_MIRROR;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
desc.AddressV = desc.AddressU;
|
|
|
|
desc.AddressW = desc.AddressU;
|
|
|
|
|
|
|
|
desc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR;
|
|
|
|
D3D11CreateSamplerState(d3d11->device, &desc, &d3d11->samplers[RARCH_FILTER_LINEAR][i]);
|
|
|
|
|
|
|
|
desc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
|
|
|
|
D3D11CreateSamplerState(d3d11->device, &desc, &d3d11->samplers[RARCH_FILTER_NEAREST][i]);
|
|
|
|
}
|
2018-01-21 04:10:45 +01:00
|
|
|
}
|
|
|
|
|
2020-03-04 23:36:22 -05:00
|
|
|
d3d11_set_filtering(d3d11, 0, video->smooth, video->ctx_scaling);
|
2018-01-24 15:00:32 +01:00
|
|
|
|
2018-01-21 04:10:45 +01:00
|
|
|
{
|
2018-04-09 18:53:26 +02:00
|
|
|
D3D11_BUFFER_DESC desc;
|
2018-01-23 18:04:55 +01:00
|
|
|
d3d11_vertex_t vertices[] = {
|
2018-01-24 15:00:32 +01:00
|
|
|
{ { 0.0f, 0.0f }, { 0.0f, 1.0f }, { 1.0f, 1.0f, 1.0f, 1.0f } },
|
|
|
|
{ { 0.0f, 1.0f }, { 0.0f, 0.0f }, { 1.0f, 1.0f, 1.0f, 1.0f } },
|
|
|
|
{ { 1.0f, 0.0f }, { 1.0f, 1.0f }, { 1.0f, 1.0f, 1.0f, 1.0f } },
|
2018-01-23 18:04:55 +01:00
|
|
|
{ { 1.0f, 1.0f }, { 1.0f, 0.0f }, { 1.0f, 1.0f, 1.0f, 1.0f } },
|
2018-01-21 04:10:45 +01:00
|
|
|
};
|
2019-02-03 15:49:35 -08:00
|
|
|
D3D11_SUBRESOURCE_DATA
|
2018-04-09 18:53:26 +02:00
|
|
|
vertexData = { vertices };
|
|
|
|
|
|
|
|
desc.ByteWidth = sizeof(vertices);
|
|
|
|
desc.Usage = D3D11_USAGE_IMMUTABLE;
|
|
|
|
desc.BindFlags = D3D11_BIND_VERTEX_BUFFER;
|
|
|
|
desc.CPUAccessFlags = 0;
|
|
|
|
desc.MiscFlags = 0;
|
|
|
|
desc.StructureByteStride = 0;
|
|
|
|
|
|
|
|
D3D11CreateBuffer(d3d11->device, &desc, &vertexData, &d3d11->frame.vbo);
|
|
|
|
desc.Usage = D3D11_USAGE_DYNAMIC;
|
|
|
|
desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
|
|
|
|
D3D11CreateBuffer(d3d11->device, &desc, &vertexData, &d3d11->menu.vbo);
|
|
|
|
|
2020-12-17 08:31:06 +01:00
|
|
|
d3d11->sprites.capacity = 16 * 1024;
|
2018-04-09 18:53:26 +02:00
|
|
|
desc.ByteWidth = sizeof(d3d11_sprite_t) * d3d11->sprites.capacity;
|
|
|
|
D3D11CreateBuffer(d3d11->device, &desc, NULL, &d3d11->sprites.vbo);
|
2018-01-21 04:10:45 +01:00
|
|
|
}
|
|
|
|
|
2021-09-03 06:15:25 +02:00
|
|
|
#ifdef HAVE_DXGI_HDR
|
|
|
|
if (d3d11->hdr.enable)
|
|
|
|
{
|
|
|
|
D3D11_INPUT_ELEMENT_DESC desc[] = {
|
|
|
|
{ "POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0,
|
|
|
|
offsetof(d3d11_vertex_t, position),
|
|
|
|
D3D11_INPUT_PER_VERTEX_DATA, 0 },
|
|
|
|
{ "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0,
|
|
|
|
offsetof(d3d11_vertex_t, texcoord),
|
|
|
|
D3D11_INPUT_PER_VERTEX_DATA, 0 },
|
|
|
|
{ "COLOR", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0,
|
|
|
|
offsetof(d3d11_vertex_t, color),
|
|
|
|
D3D11_INPUT_PER_VERTEX_DATA, 0 },
|
|
|
|
};
|
|
|
|
|
|
|
|
static const char shader[] =
|
|
|
|
#include "d3d_shaders/hdr_sm5.hlsl.h"
|
|
|
|
;
|
|
|
|
|
|
|
|
if (!d3d11_init_shader(
|
|
|
|
d3d11->device, shader, sizeof(shader),
|
|
|
|
NULL, "VSMain", "PSMain", NULL, desc,
|
2021-09-03 07:51:44 +02:00
|
|
|
countof(desc), &d3d11->shaders[VIDEO_SHADER_STOCK_HDR],
|
|
|
|
D3D11_FEATURE_LEVEL_HINT_DONTCARE
|
|
|
|
))
|
2021-09-03 06:15:25 +02:00
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2018-01-21 04:10:45 +01:00
|
|
|
{
|
2018-01-23 18:04:55 +01:00
|
|
|
D3D11_INPUT_ELEMENT_DESC desc[] = {
|
|
|
|
{ "POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, offsetof(d3d11_vertex_t, position),
|
2018-08-16 20:49:31 +02:00
|
|
|
D3D11_INPUT_PER_VERTEX_DATA, 0 },
|
2018-01-23 18:04:55 +01:00
|
|
|
{ "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, offsetof(d3d11_vertex_t, texcoord),
|
2018-08-16 20:49:31 +02:00
|
|
|
D3D11_INPUT_PER_VERTEX_DATA, 0 },
|
2018-01-23 18:04:55 +01:00
|
|
|
{ "COLOR", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, offsetof(d3d11_vertex_t, color),
|
2018-08-16 20:49:31 +02:00
|
|
|
D3D11_INPUT_PER_VERTEX_DATA, 0 },
|
2018-01-21 04:10:45 +01:00
|
|
|
};
|
|
|
|
|
2018-01-25 17:07:23 +01:00
|
|
|
static const char shader[] =
|
|
|
|
#include "d3d_shaders/opaque_sm5.hlsl.h"
|
2018-08-16 20:49:31 +02:00
|
|
|
;
|
2018-01-25 17:07:23 +01:00
|
|
|
|
2018-01-25 15:48:53 +01:00
|
|
|
if (!d3d11_init_shader(
|
2018-08-16 20:49:31 +02:00
|
|
|
d3d11->device, shader, sizeof(shader), NULL, "VSMain", "PSMain", NULL, desc,
|
2021-09-03 07:51:44 +02:00
|
|
|
countof(desc), &d3d11->shaders[VIDEO_SHADER_STOCK_BLEND],
|
|
|
|
D3D11_FEATURE_LEVEL_HINT_DONTCARE
|
|
|
|
))
|
2018-01-25 15:48:53 +01:00
|
|
|
goto error;
|
2018-01-21 04:10:45 +01:00
|
|
|
}
|
|
|
|
|
2018-01-24 20:51:19 +01:00
|
|
|
{
|
|
|
|
D3D11_INPUT_ELEMENT_DESC desc[] = {
|
|
|
|
{ "POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, offsetof(d3d11_sprite_t, pos),
|
2018-08-16 20:49:31 +02:00
|
|
|
D3D11_INPUT_PER_VERTEX_DATA, 0 },
|
2018-01-24 20:51:19 +01:00
|
|
|
{ "TEXCOORD", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, offsetof(d3d11_sprite_t, coords),
|
2018-08-16 20:49:31 +02:00
|
|
|
D3D11_INPUT_PER_VERTEX_DATA, 0 },
|
2018-01-24 20:51:19 +01:00
|
|
|
{ "COLOR", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 0, offsetof(d3d11_sprite_t, colors[0]),
|
2018-08-16 20:49:31 +02:00
|
|
|
D3D11_INPUT_PER_VERTEX_DATA, 0 },
|
2018-01-24 20:51:19 +01:00
|
|
|
{ "COLOR", 1, DXGI_FORMAT_R8G8B8A8_UNORM, 0, offsetof(d3d11_sprite_t, colors[1]),
|
2018-08-16 20:49:31 +02:00
|
|
|
D3D11_INPUT_PER_VERTEX_DATA, 0 },
|
2018-01-24 20:51:19 +01:00
|
|
|
{ "COLOR", 2, DXGI_FORMAT_R8G8B8A8_UNORM, 0, offsetof(d3d11_sprite_t, colors[2]),
|
2018-08-16 20:49:31 +02:00
|
|
|
D3D11_INPUT_PER_VERTEX_DATA, 0 },
|
2018-01-24 20:51:19 +01:00
|
|
|
{ "COLOR", 3, DXGI_FORMAT_R8G8B8A8_UNORM, 0, offsetof(d3d11_sprite_t, colors[3]),
|
2018-08-16 20:49:31 +02:00
|
|
|
D3D11_INPUT_PER_VERTEX_DATA, 0 },
|
2018-01-25 01:34:53 +01:00
|
|
|
{ "PARAMS", 0, DXGI_FORMAT_R32G32_FLOAT, 0, offsetof(d3d11_sprite_t, params),
|
2018-08-16 20:49:31 +02:00
|
|
|
D3D11_INPUT_PER_VERTEX_DATA, 0 },
|
2018-01-24 20:51:19 +01:00
|
|
|
};
|
2018-01-25 15:48:53 +01:00
|
|
|
|
2018-01-25 17:07:23 +01:00
|
|
|
static const char shader[] =
|
|
|
|
#include "d3d_shaders/sprite_sm4.hlsl.h"
|
2018-08-16 20:49:31 +02:00
|
|
|
;
|
2018-01-25 17:07:23 +01:00
|
|
|
|
2018-01-25 15:48:53 +01:00
|
|
|
if (!d3d11_init_shader(
|
2018-08-16 20:49:31 +02:00
|
|
|
d3d11->device, shader, sizeof(shader), NULL, "VSMain", "PSMain", "GSMain", desc,
|
2021-09-03 07:51:44 +02:00
|
|
|
countof(desc), &d3d11->sprites.shader,
|
|
|
|
D3D11_FEATURE_LEVEL_HINT_DONTCARE))
|
2018-01-24 20:51:19 +01:00
|
|
|
goto error;
|
2018-01-25 15:48:53 +01:00
|
|
|
if (!d3d11_init_shader(
|
2018-08-16 20:49:31 +02:00
|
|
|
d3d11->device, shader, sizeof(shader), NULL, "VSMain", "PSMainA8", "GSMain", desc,
|
2021-09-03 07:51:44 +02:00
|
|
|
countof(desc), &d3d11->sprites.shader_font,
|
|
|
|
D3D11_FEATURE_LEVEL_HINT_DONTCARE))
|
2018-01-24 20:51:19 +01:00
|
|
|
goto error;
|
|
|
|
}
|
2018-01-23 18:04:55 +01:00
|
|
|
|
2018-04-23 12:59:28 +02:00
|
|
|
if (string_is_equal(settings->arrays.menu_driver, "xmb"))
|
2018-01-25 09:48:07 +01:00
|
|
|
{
|
2018-04-23 12:59:28 +02:00
|
|
|
{
|
|
|
|
D3D11_INPUT_ELEMENT_DESC desc[] = {
|
|
|
|
{ "POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 },
|
|
|
|
};
|
2018-01-25 09:48:07 +01:00
|
|
|
|
2018-04-23 12:59:28 +02:00
|
|
|
static const char ribbon[] =
|
2018-01-25 09:48:07 +01:00
|
|
|
#include "d3d_shaders/ribbon_sm4.hlsl.h"
|
2018-02-12 01:19:43 +01:00
|
|
|
;
|
2018-04-23 12:59:28 +02:00
|
|
|
static const char ribbon_simple[] =
|
2018-01-25 17:07:23 +01:00
|
|
|
#include "d3d_shaders/ribbon_simple_sm4.hlsl.h"
|
2018-02-12 01:19:43 +01:00
|
|
|
;
|
2018-01-25 15:48:53 +01:00
|
|
|
|
2018-04-23 12:59:28 +02:00
|
|
|
if (!d3d11_init_shader(
|
|
|
|
d3d11->device, ribbon, sizeof(ribbon), NULL, "VSMain", "PSMain", NULL, desc,
|
2021-09-03 07:51:44 +02:00
|
|
|
countof(desc), &d3d11->shaders[VIDEO_SHADER_MENU],
|
|
|
|
D3D11_FEATURE_LEVEL_HINT_DONTCARE))
|
2018-04-23 12:59:28 +02:00
|
|
|
goto error;
|
2018-01-25 09:48:07 +01:00
|
|
|
|
2018-04-23 12:59:28 +02:00
|
|
|
if (!d3d11_init_shader(
|
|
|
|
d3d11->device, ribbon_simple, sizeof(ribbon_simple), NULL, "VSMain", "PSMain", NULL,
|
2021-09-03 07:51:44 +02:00
|
|
|
desc, countof(desc), &d3d11->shaders[VIDEO_SHADER_MENU_2],
|
|
|
|
D3D11_FEATURE_LEVEL_HINT_DONTCARE))
|
2018-04-23 12:59:28 +02:00
|
|
|
goto error;
|
|
|
|
}
|
2018-01-23 18:04:55 +01:00
|
|
|
|
2018-04-23 12:59:28 +02:00
|
|
|
{
|
|
|
|
D3D11_INPUT_ELEMENT_DESC desc[] = {
|
|
|
|
{ "POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, offsetof(d3d11_vertex_t, position),
|
|
|
|
D3D11_INPUT_PER_VERTEX_DATA, 0 },
|
|
|
|
{ "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, offsetof(d3d11_vertex_t, texcoord),
|
|
|
|
D3D11_INPUT_PER_VERTEX_DATA, 0 },
|
|
|
|
};
|
2018-01-25 09:48:07 +01:00
|
|
|
|
2018-04-23 12:59:28 +02:00
|
|
|
static const char simple_snow[] =
|
2018-01-25 17:07:23 +01:00
|
|
|
#include "d3d_shaders/simple_snow_sm4.hlsl.h"
|
2018-02-12 01:19:43 +01:00
|
|
|
;
|
2018-04-23 12:59:28 +02:00
|
|
|
static const char snow[] =
|
2018-01-25 17:07:23 +01:00
|
|
|
#include "d3d_shaders/snow_sm4.hlsl.h"
|
2018-02-12 01:19:43 +01:00
|
|
|
;
|
2018-04-23 12:59:28 +02:00
|
|
|
static const char bokeh[] =
|
2018-01-25 17:07:23 +01:00
|
|
|
#include "d3d_shaders/bokeh_sm4.hlsl.h"
|
2018-02-12 01:19:43 +01:00
|
|
|
;
|
2018-04-23 12:59:28 +02:00
|
|
|
static const char snowflake[] =
|
2018-01-25 17:07:23 +01:00
|
|
|
#include "d3d_shaders/snowflake_sm4.hlsl.h"
|
2018-02-12 01:19:43 +01:00
|
|
|
;
|
2018-01-25 17:07:23 +01:00
|
|
|
|
2018-04-23 12:59:28 +02:00
|
|
|
if (!d3d11_init_shader(
|
|
|
|
d3d11->device, simple_snow, sizeof(simple_snow), NULL, "VSMain", "PSMain", NULL,
|
2021-09-03 07:51:44 +02:00
|
|
|
desc, countof(desc), &d3d11->shaders[VIDEO_SHADER_MENU_3],
|
|
|
|
D3D11_FEATURE_LEVEL_HINT_DONTCARE))
|
2018-04-23 12:59:28 +02:00
|
|
|
goto error;
|
|
|
|
if (!d3d11_init_shader(
|
|
|
|
d3d11->device, snow, sizeof(snow), NULL, "VSMain", "PSMain", NULL, desc,
|
2021-09-03 07:51:44 +02:00
|
|
|
countof(desc), &d3d11->shaders[VIDEO_SHADER_MENU_4],
|
|
|
|
D3D11_FEATURE_LEVEL_HINT_DONTCARE))
|
2018-04-23 12:59:28 +02:00
|
|
|
goto error;
|
2018-01-25 15:48:53 +01:00
|
|
|
|
2018-04-23 12:59:28 +02:00
|
|
|
if (!d3d11_init_shader(
|
|
|
|
d3d11->device, bokeh, sizeof(bokeh), NULL, "VSMain", "PSMain", NULL, desc,
|
2021-09-03 07:51:44 +02:00
|
|
|
countof(desc), &d3d11->shaders[VIDEO_SHADER_MENU_5],
|
|
|
|
D3D11_FEATURE_LEVEL_HINT_DONTCARE))
|
2018-04-23 12:59:28 +02:00
|
|
|
goto error;
|
2018-01-25 09:48:07 +01:00
|
|
|
|
2018-04-23 12:59:28 +02:00
|
|
|
if (!d3d11_init_shader(
|
|
|
|
d3d11->device, snowflake, sizeof(snowflake), NULL, "VSMain", "PSMain", NULL, desc,
|
2021-09-03 07:51:44 +02:00
|
|
|
countof(desc), &d3d11->shaders[VIDEO_SHADER_MENU_6],
|
|
|
|
D3D11_FEATURE_LEVEL_HINT_DONTCARE))
|
2018-04-23 12:59:28 +02:00
|
|
|
goto error;
|
|
|
|
}
|
2018-01-25 09:48:07 +01:00
|
|
|
}
|
|
|
|
|
2018-01-23 18:04:55 +01:00
|
|
|
{
|
2018-02-04 20:03:27 +01:00
|
|
|
D3D11_BLEND_DESC blend_desc = { 0 };
|
|
|
|
|
|
|
|
blend_desc.AlphaToCoverageEnable = FALSE;
|
|
|
|
blend_desc.IndependentBlendEnable = FALSE;
|
|
|
|
blend_desc.RenderTarget[0].BlendEnable = TRUE;
|
|
|
|
blend_desc.RenderTarget[0].SrcBlend = D3D11_BLEND_SRC_ALPHA;
|
|
|
|
blend_desc.RenderTarget[0].DestBlend = D3D11_BLEND_INV_SRC_ALPHA;
|
|
|
|
blend_desc.RenderTarget[0].BlendOp = D3D11_BLEND_OP_ADD;
|
|
|
|
blend_desc.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_SRC_ALPHA;
|
|
|
|
blend_desc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_INV_SRC_ALPHA;
|
|
|
|
blend_desc.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD;
|
|
|
|
blend_desc.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;
|
2018-01-23 18:04:55 +01:00
|
|
|
D3D11CreateBlendState(d3d11->device, &blend_desc, &d3d11->blend_enable);
|
2018-01-25 09:48:07 +01:00
|
|
|
|
2018-01-25 15:48:53 +01:00
|
|
|
blend_desc.RenderTarget[0].SrcBlend = D3D11_BLEND_ONE;
|
2018-01-25 09:48:07 +01:00
|
|
|
blend_desc.RenderTarget[0].DestBlend = D3D11_BLEND_ONE;
|
|
|
|
D3D11CreateBlendState(d3d11->device, &blend_desc, &d3d11->blend_pipeline);
|
|
|
|
|
2018-01-23 18:04:55 +01:00
|
|
|
blend_desc.RenderTarget[0].BlendEnable = FALSE;
|
|
|
|
D3D11CreateBlendState(d3d11->device, &blend_desc, &d3d11->blend_disable);
|
|
|
|
}
|
2018-01-24 20:51:19 +01:00
|
|
|
{
|
2018-02-12 01:19:43 +01:00
|
|
|
D3D11_RASTERIZER_DESC desc = { (D3D11_FILL_MODE)0 };
|
2018-02-04 20:03:27 +01:00
|
|
|
|
|
|
|
desc.FillMode = D3D11_FILL_SOLID;
|
|
|
|
desc.CullMode = D3D11_CULL_NONE;
|
2020-11-15 13:01:55 +01:00
|
|
|
|
2019-01-26 18:52:49 -05:00
|
|
|
desc.ScissorEnable = TRUE;
|
2020-11-15 13:01:55 +01:00
|
|
|
D3D11CreateRasterizerState(d3d11->device, &desc, &d3d11->scissor_enabled);
|
2018-02-04 20:03:27 +01:00
|
|
|
|
2020-11-15 13:01:55 +01:00
|
|
|
desc.ScissorEnable = FALSE;
|
|
|
|
D3D11CreateRasterizerState(d3d11->device, &desc, &d3d11->scissor_disabled);
|
2018-01-24 20:51:19 +01:00
|
|
|
}
|
|
|
|
|
2020-02-16 21:59:03 +01:00
|
|
|
font_driver_init_osd(d3d11,
|
|
|
|
video,
|
|
|
|
false,
|
|
|
|
video->is_threaded,
|
|
|
|
FONT_DRIVER_RENDER_D3D11_API);
|
2018-01-21 04:10:45 +01:00
|
|
|
|
2019-06-17 14:10:55 +02:00
|
|
|
{
|
2020-08-16 03:11:00 +02:00
|
|
|
d3d11_fake_context.get_flags = d3d11_get_flags;
|
2020-01-03 09:33:20 +08:00
|
|
|
d3d11_fake_context.get_metrics = win32_get_metrics;
|
2019-06-19 18:05:21 +02:00
|
|
|
video_context_driver_set(&d3d11_fake_context);
|
2020-08-16 03:11:00 +02:00
|
|
|
const char *shader_preset = retroarch_get_shader_preset();
|
|
|
|
enum rarch_shader_type type = video_shader_parse_type(shader_preset);
|
2019-06-17 14:10:55 +02:00
|
|
|
d3d11_gfx_set_shader(d3d11, type, shader_preset);
|
|
|
|
}
|
2018-01-31 01:08:36 +01:00
|
|
|
|
2018-03-25 23:14:14 +01:00
|
|
|
if (video_driver_get_hw_context()->context_type == RETRO_HW_CONTEXT_DIRECT3D &&
|
2018-08-16 20:49:31 +02:00
|
|
|
video_driver_get_hw_context()->version_major == 11)
|
2018-03-25 23:14:14 +01:00
|
|
|
{
|
|
|
|
d3d11->hw.enable = true;
|
|
|
|
d3d11->hw.iface.interface_type = RETRO_HW_RENDER_INTERFACE_D3D11;
|
|
|
|
d3d11->hw.iface.interface_version = RETRO_HW_RENDER_INTERFACE_D3D11_VERSION;
|
|
|
|
d3d11->hw.iface.handle = d3d11;
|
|
|
|
d3d11->hw.iface.device = d3d11->device;
|
|
|
|
d3d11->hw.iface.context = d3d11->context;
|
|
|
|
d3d11->hw.iface.featureLevel = d3d11->supportedFeatureLevel;
|
|
|
|
d3d11->hw.iface.D3DCompile = D3DCompile;
|
|
|
|
}
|
|
|
|
|
2019-03-07 19:17:54 -05:00
|
|
|
{
|
2020-02-18 14:51:40 +01:00
|
|
|
int i = 0;
|
|
|
|
int gpu_index = settings->ints.d3d11_gpu_index;
|
2019-03-07 19:17:54 -05:00
|
|
|
|
2020-08-03 12:36:51 +02:00
|
|
|
if (d3d11->gpu_list)
|
|
|
|
string_list_free(d3d11->gpu_list);
|
2019-06-18 16:33:37 -04:00
|
|
|
|
2020-08-03 12:36:51 +02:00
|
|
|
d3d11->gpu_list = string_list_new();
|
2019-03-07 19:17:54 -05:00
|
|
|
|
2020-02-01 04:15:22 +01:00
|
|
|
for (;;)
|
2019-03-07 19:17:54 -05:00
|
|
|
{
|
2019-06-18 16:33:37 -04:00
|
|
|
DXGI_ADAPTER_DESC desc = {0};
|
|
|
|
char str[128];
|
|
|
|
union string_list_elem_attr attr = {0};
|
|
|
|
|
|
|
|
str[0] = '\0';
|
|
|
|
|
2019-03-07 19:17:54 -05:00
|
|
|
#ifdef __WINRT__
|
2019-06-18 16:33:37 -04:00
|
|
|
if (FAILED(DXGIEnumAdapters2(d3d11->factory, i, &d3d11->adapter)))
|
2019-03-07 19:17:54 -05:00
|
|
|
break;
|
|
|
|
#else
|
2019-06-18 16:33:37 -04:00
|
|
|
if (FAILED(DXGIEnumAdapters(d3d11->factory, i, &d3d11->adapter)))
|
2019-03-07 19:17:54 -05:00
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
IDXGIAdapter_GetDesc(d3d11->adapter, &desc);
|
|
|
|
|
2019-03-14 14:14:44 +01:00
|
|
|
utf16_to_char_string((const uint16_t*)
|
|
|
|
desc.Description, str, sizeof(str));
|
2019-03-07 19:17:54 -05:00
|
|
|
|
2021-12-04 15:21:12 +02:00
|
|
|
RARCH_LOG("[D3D11]: Found GPU at index %d: \"%s\".\n", i, str);
|
2019-06-18 16:33:37 -04:00
|
|
|
|
2020-08-03 12:36:51 +02:00
|
|
|
string_list_append(d3d11->gpu_list, str, attr);
|
2019-03-07 19:17:54 -05:00
|
|
|
|
2019-06-18 16:33:37 -04:00
|
|
|
if (i < D3D11_MAX_GPU_COUNT)
|
2020-08-03 12:36:51 +02:00
|
|
|
d3d11->adapters[i] = d3d11->adapter;
|
2019-06-18 16:33:37 -04:00
|
|
|
|
|
|
|
i++;
|
|
|
|
}
|
2019-03-07 19:17:54 -05:00
|
|
|
|
2020-08-03 12:36:51 +02:00
|
|
|
video_driver_set_gpu_api_devices(GFX_CTX_DIRECT3D11_API, d3d11->gpu_list);
|
2019-03-07 19:17:54 -05:00
|
|
|
|
2020-02-18 14:51:40 +01:00
|
|
|
if (0 <= gpu_index && gpu_index <= i && gpu_index < D3D11_MAX_GPU_COUNT)
|
2019-06-18 16:33:37 -04:00
|
|
|
{
|
2020-08-03 12:36:51 +02:00
|
|
|
d3d11->current_adapter = d3d11->adapters[gpu_index];
|
|
|
|
d3d11->adapter = d3d11->current_adapter;
|
2020-02-18 14:51:40 +01:00
|
|
|
RARCH_LOG("[D3D11]: Using GPU index %d.\n", gpu_index);
|
2020-08-03 12:36:51 +02:00
|
|
|
video_driver_set_gpu_device_string(d3d11->gpu_list->elems[gpu_index].data);
|
2019-06-18 16:33:37 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-02-18 14:51:40 +01:00
|
|
|
RARCH_WARN("[D3D11]: Invalid GPU index %d, using first device found.\n", gpu_index);
|
2020-08-03 12:36:51 +02:00
|
|
|
d3d11->current_adapter = d3d11->adapters[0];
|
|
|
|
d3d11->adapter = d3d11->current_adapter;
|
2019-03-07 19:17:54 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-21 04:10:45 +01:00
|
|
|
return d3d11;
|
|
|
|
|
|
|
|
error:
|
2018-01-24 20:51:19 +01:00
|
|
|
d3d11_gfx_free(d3d11);
|
2020-01-03 09:44:24 +08:00
|
|
|
|
|
|
|
#ifdef HAVE_OPENGL
|
2021-09-28 00:50:48 +02:00
|
|
|
video_driver_force_fallback("gl");
|
2020-01-03 09:44:24 +08:00
|
|
|
#elif !defined(__WINRT__)
|
|
|
|
#ifdef HAVE_OPENGL1
|
2021-09-28 00:50:48 +02:00
|
|
|
video_driver_force_fallback("gl1");
|
2020-01-03 09:44:24 +08:00
|
|
|
#else
|
2021-09-28 00:50:48 +02:00
|
|
|
video_driver_force_fallback("gdi");
|
2020-01-03 09:44:24 +08:00
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2018-01-21 04:10:45 +01:00
|
|
|
return NULL;
|
|
|
|
}
|
2018-02-03 13:29:00 +01:00
|
|
|
|
|
|
|
static void d3d11_init_history(d3d11_video_t* d3d11, unsigned width, unsigned height)
|
2018-01-31 01:08:36 +01:00
|
|
|
{
|
2018-02-03 15:16:04 +01:00
|
|
|
unsigned i;
|
|
|
|
|
2018-02-03 13:29:00 +01:00
|
|
|
/* todo: should we init history to max_width/max_height instead ?
|
|
|
|
* to prevent out of memory errors happening several frames later
|
|
|
|
* and to reduce memory fragmentation */
|
|
|
|
|
|
|
|
assert(d3d11->shader_preset);
|
2018-04-21 05:20:22 +02:00
|
|
|
for (i = 0; i < (unsigned)d3d11->shader_preset->history_size + 1; i++)
|
2018-01-31 01:08:36 +01:00
|
|
|
{
|
2018-02-03 13:29:00 +01:00
|
|
|
d3d11->frame.texture[i].desc.Width = width;
|
|
|
|
d3d11->frame.texture[i].desc.Height = height;
|
|
|
|
d3d11->frame.texture[i].desc.Format = d3d11->frame.texture[0].desc.Format;
|
|
|
|
d3d11->frame.texture[i].desc.Usage = d3d11->frame.texture[0].desc.Usage;
|
|
|
|
d3d11_init_texture(d3d11->device, &d3d11->frame.texture[i]);
|
|
|
|
/* todo: clear texture ? */
|
2018-01-31 01:08:36 +01:00
|
|
|
}
|
2018-02-03 13:29:00 +01:00
|
|
|
d3d11->init_history = false;
|
|
|
|
}
|
2018-04-21 03:27:41 +02:00
|
|
|
|
2018-02-03 13:29:00 +01:00
|
|
|
static void d3d11_init_render_targets(d3d11_video_t* d3d11, unsigned width, unsigned height)
|
|
|
|
{
|
2018-02-03 15:16:04 +01:00
|
|
|
unsigned i;
|
|
|
|
|
2018-02-03 13:29:00 +01:00
|
|
|
assert(d3d11->shader_preset);
|
2018-01-31 01:08:36 +01:00
|
|
|
|
2018-02-03 15:16:04 +01:00
|
|
|
for (i = 0; i < d3d11->shader_preset->passes; i++)
|
2018-01-31 01:08:36 +01:00
|
|
|
{
|
2018-02-03 13:29:00 +01:00
|
|
|
struct video_shader_pass* pass = &d3d11->shader_preset->pass[i];
|
|
|
|
|
|
|
|
if (pass->fbo.valid)
|
2018-01-31 01:08:36 +01:00
|
|
|
{
|
|
|
|
|
2018-02-03 13:29:00 +01:00
|
|
|
switch (pass->fbo.type_x)
|
2018-01-31 01:08:36 +01:00
|
|
|
{
|
2018-02-03 13:29:00 +01:00
|
|
|
case RARCH_SCALE_INPUT:
|
|
|
|
width *= pass->fbo.scale_x;
|
|
|
|
break;
|
2018-01-31 01:08:36 +01:00
|
|
|
|
2018-02-03 13:29:00 +01:00
|
|
|
case RARCH_SCALE_VIEWPORT:
|
|
|
|
width = d3d11->vp.width * pass->fbo.scale_x;
|
|
|
|
break;
|
2018-01-31 01:08:36 +01:00
|
|
|
|
2018-02-03 13:29:00 +01:00
|
|
|
case RARCH_SCALE_ABSOLUTE:
|
|
|
|
width = pass->fbo.abs_x;
|
|
|
|
break;
|
2018-01-31 01:08:36 +01:00
|
|
|
|
2018-02-03 13:29:00 +01:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2018-01-31 01:08:36 +01:00
|
|
|
|
2018-02-03 13:29:00 +01:00
|
|
|
if (!width)
|
|
|
|
width = d3d11->vp.width;
|
2018-01-31 01:08:36 +01:00
|
|
|
|
2018-02-03 13:29:00 +01:00
|
|
|
switch (pass->fbo.type_y)
|
|
|
|
{
|
|
|
|
case RARCH_SCALE_INPUT:
|
|
|
|
height *= pass->fbo.scale_y;
|
|
|
|
break;
|
2018-01-31 01:08:36 +01:00
|
|
|
|
2018-02-03 13:29:00 +01:00
|
|
|
case RARCH_SCALE_VIEWPORT:
|
|
|
|
height = d3d11->vp.height * pass->fbo.scale_y;
|
|
|
|
break;
|
2018-01-31 01:08:36 +01:00
|
|
|
|
2018-02-03 13:29:00 +01:00
|
|
|
case RARCH_SCALE_ABSOLUTE:
|
|
|
|
height = pass->fbo.abs_y;
|
|
|
|
break;
|
2018-02-02 14:39:53 +01:00
|
|
|
|
2018-02-03 13:29:00 +01:00
|
|
|
default:
|
|
|
|
break;
|
2018-02-02 14:39:53 +01:00
|
|
|
}
|
|
|
|
|
2018-02-03 13:29:00 +01:00
|
|
|
if (!height)
|
|
|
|
height = d3d11->vp.height;
|
|
|
|
}
|
|
|
|
else if (i == (d3d11->shader_preset->passes - 1))
|
|
|
|
{
|
|
|
|
width = d3d11->vp.width;
|
|
|
|
height = d3d11->vp.height;
|
|
|
|
}
|
2018-01-31 01:08:36 +01:00
|
|
|
|
2021-12-04 15:21:12 +02:00
|
|
|
RARCH_LOG("[D3D11]: Updating framebuffer size %ux%u.\n", width, height);
|
2018-02-02 19:57:45 +01:00
|
|
|
|
2018-02-03 13:29:00 +01:00
|
|
|
if ((i != (d3d11->shader_preset->passes - 1)) || (width != d3d11->vp.width) ||
|
2018-08-16 20:49:31 +02:00
|
|
|
(height != d3d11->vp.height))
|
2018-02-03 13:29:00 +01:00
|
|
|
{
|
|
|
|
d3d11->pass[i].viewport.Width = width;
|
|
|
|
d3d11->pass[i].viewport.Height = height;
|
|
|
|
d3d11->pass[i].viewport.MaxDepth = 1.0;
|
|
|
|
d3d11->pass[i].rt.desc.Width = width;
|
|
|
|
d3d11->pass[i].rt.desc.Height = height;
|
|
|
|
d3d11->pass[i].rt.desc.BindFlags = D3D11_BIND_RENDER_TARGET;
|
|
|
|
d3d11->pass[i].rt.desc.Format = glslang_format_to_dxgi(d3d11->pass[i].semantics.format);
|
|
|
|
d3d11_init_texture(d3d11->device, &d3d11->pass[i].rt);
|
|
|
|
|
|
|
|
if (pass->feedback)
|
2018-01-31 01:08:36 +01:00
|
|
|
{
|
2018-02-03 13:29:00 +01:00
|
|
|
d3d11->pass[i].feedback.desc = d3d11->pass[i].rt.desc;
|
|
|
|
d3d11_init_texture(d3d11->device, &d3d11->pass[i].feedback);
|
|
|
|
/* todo: do we need to clear it to black here ? */
|
2018-01-31 01:08:36 +01:00
|
|
|
}
|
|
|
|
}
|
2018-02-03 13:29:00 +01:00
|
|
|
else
|
|
|
|
{
|
|
|
|
d3d11->pass[i].rt.size_data.x = width;
|
|
|
|
d3d11->pass[i].rt.size_data.y = height;
|
|
|
|
d3d11->pass[i].rt.size_data.z = 1.0f / width;
|
|
|
|
d3d11->pass[i].rt.size_data.w = 1.0f / height;
|
|
|
|
}
|
2018-01-31 01:08:36 +01:00
|
|
|
}
|
|
|
|
|
2018-02-03 13:29:00 +01:00
|
|
|
d3d11->resize_render_targets = false;
|
2018-02-01 20:56:40 +01:00
|
|
|
|
2018-01-31 01:08:36 +01:00
|
|
|
#if 0
|
|
|
|
error:
|
|
|
|
d3d11_free_shader_preset(d3d11);
|
|
|
|
return false;
|
|
|
|
#endif
|
|
|
|
}
|
2018-01-21 04:10:45 +01:00
|
|
|
|
2018-01-23 18:04:55 +01:00
|
|
|
static bool d3d11_gfx_frame(
|
|
|
|
void* data,
|
|
|
|
const void* frame,
|
|
|
|
unsigned width,
|
|
|
|
unsigned height,
|
|
|
|
uint64_t frame_count,
|
|
|
|
unsigned pitch,
|
|
|
|
const char* msg,
|
|
|
|
video_frame_info_t* video_info)
|
2018-01-21 04:10:45 +01:00
|
|
|
{
|
2018-02-04 20:03:27 +01:00
|
|
|
unsigned i;
|
2020-11-15 13:01:55 +01:00
|
|
|
d3d11_texture_t* texture = NULL;
|
2020-12-17 14:39:58 +01:00
|
|
|
D3D11RenderTargetView rtv = NULL;
|
2020-11-15 13:01:55 +01:00
|
|
|
d3d11_video_t* d3d11 = (d3d11_video_t*)data;
|
|
|
|
D3D11DeviceContext context = d3d11->context;
|
2021-06-04 02:33:21 +03:00
|
|
|
bool vsync = d3d11->vsync;
|
2021-06-22 13:44:47 +10:00
|
|
|
unsigned present_flags = (vsync || !d3d11->has_allow_tearing) ? 0 : DXGI_PRESENT_ALLOW_TEARING;
|
2020-11-15 13:01:55 +01:00
|
|
|
const char *stat_text = video_info->stat_text;
|
|
|
|
unsigned video_width = video_info->width;
|
|
|
|
unsigned video_height = video_info->height;
|
|
|
|
bool statistics_show = video_info->statistics_show;
|
|
|
|
struct font_params* osd_params = (struct font_params*)&video_info->osd_stat_params;
|
|
|
|
bool menu_is_alive = video_info->menu_is_alive;
|
2021-12-26 05:56:44 +02:00
|
|
|
bool overlay_behind_menu = video_info->overlay_behind_menu;
|
2020-08-03 16:33:54 +02:00
|
|
|
#ifdef HAVE_GFX_WIDGETS
|
2020-11-15 13:01:55 +01:00
|
|
|
bool widgets_active = video_info->widgets_active;
|
2020-08-03 16:33:54 +02:00
|
|
|
#endif
|
2021-09-03 06:15:25 +02:00
|
|
|
#ifdef HAVE_DXGI_HDR
|
|
|
|
bool video_hdr_enable = video_info->hdr_enable;
|
2018-01-22 07:35:36 +01:00
|
|
|
|
2021-09-03 06:15:25 +02:00
|
|
|
if ( d3d11->resize_chain ||
|
|
|
|
(d3d11->hdr.enable != video_hdr_enable))
|
|
|
|
#else
|
2018-01-24 15:00:32 +01:00
|
|
|
if (d3d11->resize_chain)
|
2021-09-03 06:15:25 +02:00
|
|
|
#endif
|
2018-01-23 20:27:03 +01:00
|
|
|
{
|
2021-09-03 06:15:25 +02:00
|
|
|
UINT swapchain_flags = d3d11->has_allow_tearing
|
2021-06-22 00:41:56 +02:00
|
|
|
? DXGI_SWAP_CHAIN_FLAG_ALLOW_TEARING : 0;
|
2021-09-03 06:15:25 +02:00
|
|
|
#ifdef HAVE_DXGI_HDR
|
|
|
|
d3d11->hdr.enable = video_hdr_enable;
|
|
|
|
|
|
|
|
if(d3d11->hdr.enable)
|
|
|
|
d3d11_release_texture(&d3d11->back_buffer);
|
|
|
|
DXGIResizeBuffers(d3d11->swapChain, 0, 0, 0,
|
|
|
|
d3d11->chain_formats[d3d11->chain_bit_depth],
|
|
|
|
swapchain_flags);
|
|
|
|
#else
|
|
|
|
DXGIResizeBuffers(d3d11->swapChain, 0, 0, 0,
|
|
|
|
DXGI_FORMAT_UNKNOWN,
|
2021-06-22 00:41:56 +02:00
|
|
|
swapchain_flags);
|
2021-09-03 06:15:25 +02:00
|
|
|
#endif
|
2018-01-23 20:27:03 +01:00
|
|
|
|
2021-09-03 06:15:25 +02:00
|
|
|
d3d11->viewport.Width = video_width;
|
|
|
|
d3d11->viewport.Height = video_height;
|
|
|
|
d3d11->scissor.right = video_width;
|
|
|
|
d3d11->scissor.bottom = video_height;
|
2018-01-23 20:27:03 +01:00
|
|
|
|
2018-01-25 09:48:07 +01:00
|
|
|
d3d11->ubo_values.OutputSize.width = d3d11->viewport.Width;
|
|
|
|
d3d11->ubo_values.OutputSize.height = d3d11->viewport.Height;
|
|
|
|
|
2021-09-03 06:15:25 +02:00
|
|
|
d3d11->resize_chain = false;
|
|
|
|
d3d11->resize_viewport = true;
|
2020-03-08 01:45:29 +01:00
|
|
|
video_driver_set_size(video_width, video_height);
|
2021-09-03 06:15:25 +02:00
|
|
|
|
|
|
|
#ifdef HAVE_DXGI_HDR
|
|
|
|
#ifdef __WINRT__
|
|
|
|
if (!(d3d11->hdr.support =
|
|
|
|
dxgi_check_display_hdr_support(d3d11->factory, uwp_get_corewindow())))
|
|
|
|
d3d11->hdr.enable = false;
|
|
|
|
#else
|
|
|
|
if (!(d3d11->hdr.support =
|
|
|
|
dxgi_check_display_hdr_support(d3d11->factory, main_window.hwnd)))
|
|
|
|
d3d11->hdr.enable = false;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if(d3d11->hdr.enable)
|
|
|
|
{
|
|
|
|
memset(&d3d11->back_buffer, 0, sizeof(d3d11->back_buffer));
|
|
|
|
d3d11->back_buffer.desc.Width = video_width;
|
|
|
|
d3d11->back_buffer.desc.Height = video_height;
|
2021-12-22 01:17:17 +00:00
|
|
|
d3d11->back_buffer.desc.Format = d3d11->shader_preset && d3d11->shader_preset->passes ? glslang_format_to_dxgi(d3d11->pass[d3d11->shader_preset->passes - 1].semantics.format) : DXGI_FORMAT_R8G8B8A8_UNORM;
|
2021-09-03 06:15:25 +02:00
|
|
|
d3d11->back_buffer.desc.BindFlags = D3D11_BIND_RENDER_TARGET;
|
|
|
|
d3d11_init_texture(d3d11->device, &d3d11->back_buffer);
|
|
|
|
|
|
|
|
dxgi_swapchain_color_space(
|
|
|
|
d3d11->swapChain,
|
|
|
|
&d3d11->chain_color_space,
|
|
|
|
DXGI_COLOR_SPACE_RGB_FULL_G2084_NONE_P2020);
|
2021-09-13 15:54:50 +01:00
|
|
|
|
|
|
|
d3d11->chain_bit_depth = DXGI_SWAPCHAIN_BIT_DEPTH_10;
|
2021-09-03 06:15:25 +02:00
|
|
|
}
|
|
|
|
else
|
2021-09-13 15:54:50 +01:00
|
|
|
{
|
2021-09-03 06:15:25 +02:00
|
|
|
dxgi_swapchain_color_space(
|
|
|
|
d3d11->swapChain,
|
|
|
|
&d3d11->chain_color_space,
|
|
|
|
DXGI_COLOR_SPACE_RGB_FULL_G22_NONE_P709);
|
|
|
|
|
2021-09-13 15:54:50 +01:00
|
|
|
d3d11->chain_bit_depth = DXGI_SWAPCHAIN_BIT_DEPTH_8;
|
|
|
|
}
|
|
|
|
|
2021-09-03 06:15:25 +02:00
|
|
|
dxgi_set_hdr_metadata(
|
|
|
|
d3d11->swapChain,
|
|
|
|
d3d11->hdr.support,
|
|
|
|
d3d11->chain_bit_depth,
|
|
|
|
d3d11->chain_color_space,
|
|
|
|
d3d11->hdr.max_output_nits,
|
|
|
|
d3d11->hdr.min_output_nits,
|
|
|
|
d3d11->hdr.max_cll,
|
|
|
|
d3d11->hdr.max_fall);
|
|
|
|
#endif
|
2018-01-23 20:27:03 +01:00
|
|
|
}
|
|
|
|
|
2020-12-17 14:39:58 +01:00
|
|
|
{
|
2021-09-03 06:15:25 +02:00
|
|
|
D3D11Texture2D back_buffer;
|
|
|
|
DXGIGetSwapChainBufferD3D11(d3d11->swapChain, 0, &back_buffer);
|
|
|
|
D3D11CreateTexture2DRenderTargetView(d3d11->device, back_buffer, NULL, &rtv);
|
|
|
|
Release(back_buffer);
|
2020-12-17 14:39:58 +01:00
|
|
|
}
|
|
|
|
|
2020-03-08 01:45:29 +01:00
|
|
|
/* custom viewport doesn't call apply_state_changes, so we can't rely on this for now */
|
|
|
|
#if 0
|
2018-01-31 01:08:36 +01:00
|
|
|
if (d3d11->resize_viewport)
|
|
|
|
#endif
|
2018-08-16 20:49:31 +02:00
|
|
|
d3d11_update_viewport(d3d11, false);
|
2018-01-31 01:08:36 +01:00
|
|
|
|
2018-01-23 18:04:55 +01:00
|
|
|
if (frame && width && height)
|
2018-01-21 04:10:45 +01:00
|
|
|
{
|
2020-11-15 13:01:55 +01:00
|
|
|
D3D11Texture2D hw_texture = NULL;
|
|
|
|
if (frame == RETRO_HW_FRAME_BUFFER_VALID)
|
|
|
|
{
|
2020-11-15 15:07:53 +01:00
|
|
|
D3D11_SHADER_RESOURCE_VIEW_DESC hw_desc;
|
2020-11-15 13:01:55 +01:00
|
|
|
D3D11ShaderResourceView hw_view = NULL;
|
|
|
|
D3D11GetPShaderResources(context, 0, 1, &hw_view);
|
2020-11-15 15:07:53 +01:00
|
|
|
D3D11GetShaderResourceViewDesc(hw_view, &hw_desc);
|
2020-11-15 13:01:55 +01:00
|
|
|
D3D11GetShaderResourceViewTexture2D(hw_view, &hw_texture);
|
|
|
|
|
|
|
|
if (d3d11->frame.texture[0].desc.Format != hw_desc.Format)
|
|
|
|
{
|
|
|
|
d3d11->frame.texture[0].desc.Width = width;
|
|
|
|
d3d11->frame.texture[0].desc.Height = height;
|
|
|
|
d3d11->frame.texture[0].desc.Format = hw_desc.Format;
|
|
|
|
d3d11_init_texture(d3d11->device, &d3d11->frame.texture[0]);
|
|
|
|
|
|
|
|
d3d11->init_history = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
Release(hw_view);
|
|
|
|
}
|
|
|
|
|
2018-02-03 13:29:00 +01:00
|
|
|
if (d3d11->shader_preset)
|
|
|
|
{
|
|
|
|
if (d3d11->frame.texture[0].desc.Width != width ||
|
2018-08-16 20:49:31 +02:00
|
|
|
d3d11->frame.texture[0].desc.Height != height)
|
2018-02-03 13:29:00 +01:00
|
|
|
d3d11->resize_render_targets = true;
|
|
|
|
|
|
|
|
if (d3d11->resize_render_targets)
|
|
|
|
{
|
|
|
|
/* release all render targets first to avoid memory fragmentation */
|
2018-02-03 15:16:04 +01:00
|
|
|
for (i = 0; i < d3d11->shader_preset->passes; i++)
|
2018-02-11 22:56:37 +01:00
|
|
|
{
|
2018-02-03 13:29:00 +01:00
|
|
|
d3d11_release_texture(&d3d11->pass[i].rt);
|
2018-02-11 22:56:37 +01:00
|
|
|
d3d11_release_texture(&d3d11->pass[i].feedback);
|
|
|
|
memset(&d3d11->pass[i].rt, 0, sizeof(d3d11->pass[i].rt));
|
|
|
|
memset(&d3d11->pass[i].feedback, 0, sizeof(d3d11->pass[i].feedback));
|
|
|
|
}
|
2018-02-03 13:29:00 +01:00
|
|
|
}
|
2018-02-01 20:56:40 +01:00
|
|
|
|
2018-02-03 13:29:00 +01:00
|
|
|
if (d3d11->shader_preset->history_size)
|
|
|
|
{
|
|
|
|
if (d3d11->init_history)
|
|
|
|
d3d11_init_history(d3d11, width, height);
|
|
|
|
else
|
|
|
|
{
|
2018-02-03 15:16:04 +01:00
|
|
|
int k;
|
2018-02-03 13:29:00 +01:00
|
|
|
d3d11_texture_t tmp = d3d11->frame.texture[d3d11->shader_preset->history_size];
|
2018-02-03 15:16:04 +01:00
|
|
|
for (k = d3d11->shader_preset->history_size; k > 0; k--)
|
|
|
|
d3d11->frame.texture[k] = d3d11->frame.texture[k - 1];
|
2018-02-03 13:29:00 +01:00
|
|
|
d3d11->frame.texture[0] = tmp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* either no history, or we moved a texture of a different size in the front slot */
|
|
|
|
if (d3d11->frame.texture[0].desc.Width != width ||
|
2018-08-16 20:49:31 +02:00
|
|
|
d3d11->frame.texture[0].desc.Height != height)
|
2018-02-03 13:29:00 +01:00
|
|
|
{
|
|
|
|
d3d11->frame.texture[0].desc.Width = width;
|
|
|
|
d3d11->frame.texture[0].desc.Height = height;
|
|
|
|
d3d11_init_texture(d3d11->device, &d3d11->frame.texture[0]);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (d3d11->resize_render_targets)
|
|
|
|
d3d11_init_render_targets(d3d11, width, height);
|
2018-01-21 04:10:45 +01:00
|
|
|
|
2020-11-15 13:01:55 +01:00
|
|
|
if (hw_texture)
|
2020-10-01 00:05:49 +10:00
|
|
|
{
|
2020-11-15 13:01:55 +01:00
|
|
|
D3D11_BOX frame_box = { 0, 0, 0, width, height, 1 };
|
|
|
|
D3D11CopyTexture2DSubresourceRegion(
|
|
|
|
context, d3d11->frame.texture[0].handle, 0, 0, 0, 0, hw_texture, 0, &frame_box);
|
|
|
|
Release(hw_texture);
|
|
|
|
hw_texture = NULL;
|
|
|
|
}
|
|
|
|
else
|
2018-03-25 23:14:14 +01:00
|
|
|
d3d11_update_texture(
|
|
|
|
context, width, height, pitch, d3d11->format, frame, &d3d11->frame.texture[0]);
|
2018-01-23 18:04:55 +01:00
|
|
|
}
|
2018-01-21 04:10:45 +01:00
|
|
|
|
2020-11-15 13:01:55 +01:00
|
|
|
D3D11SetRasterizerState(context, d3d11->scissor_disabled);
|
2018-02-03 13:29:00 +01:00
|
|
|
D3D11SetBlendState(context, d3d11->blend_disable, NULL, D3D11_DEFAULT_SAMPLE_MASK);
|
2020-11-15 13:01:55 +01:00
|
|
|
D3D11SetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
|
|
|
|
D3D11SetVertexBuffer(context, 0, d3d11->frame.vbo, sizeof(d3d11_vertex_t), 0);
|
2018-01-24 15:00:32 +01:00
|
|
|
|
2020-11-15 13:01:55 +01:00
|
|
|
texture = d3d11->frame.texture;
|
2018-01-31 01:08:36 +01:00
|
|
|
|
2020-11-15 13:01:55 +01:00
|
|
|
if (d3d11->shader_preset)
|
2018-01-31 01:08:36 +01:00
|
|
|
{
|
2018-02-03 15:16:04 +01:00
|
|
|
for (i = 0; i < d3d11->shader_preset->passes; i++)
|
2018-01-31 01:08:36 +01:00
|
|
|
{
|
2018-02-02 19:57:45 +01:00
|
|
|
if (d3d11->shader_preset->pass[i].feedback)
|
|
|
|
{
|
|
|
|
d3d11_texture_t tmp = d3d11->pass[i].feedback;
|
|
|
|
d3d11->pass[i].feedback = d3d11->pass[i].rt;
|
|
|
|
d3d11->pass[i].rt = tmp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-03 15:16:04 +01:00
|
|
|
for (i = 0; i < d3d11->shader_preset->passes; i++)
|
2018-02-02 19:57:45 +01:00
|
|
|
{
|
2018-02-03 15:16:04 +01:00
|
|
|
unsigned j;
|
|
|
|
|
2018-02-03 13:29:00 +01:00
|
|
|
d3d11_set_shader(context, &d3d11->pass[i].shader);
|
2018-02-02 19:57:45 +01:00
|
|
|
|
2018-01-31 01:08:36 +01:00
|
|
|
if (d3d11->shader_preset->pass[i].frame_count_mod)
|
|
|
|
d3d11->pass[i].frame_count =
|
2018-08-16 20:49:31 +02:00
|
|
|
frame_count % d3d11->shader_preset->pass[i].frame_count_mod;
|
2018-01-31 01:08:36 +01:00
|
|
|
else
|
|
|
|
d3d11->pass[i].frame_count = frame_count;
|
|
|
|
|
2020-07-01 21:04:05 +02:00
|
|
|
#ifdef HAVE_REWIND
|
2019-05-29 18:09:37 +02:00
|
|
|
d3d11->pass[i].frame_direction = state_manager_frame_is_reversed() ? -1 : 1;
|
2020-07-01 21:04:05 +02:00
|
|
|
#else
|
|
|
|
d3d11->pass[i].frame_direction = 1;
|
|
|
|
#endif
|
2019-05-29 18:09:37 +02:00
|
|
|
|
2018-02-03 15:16:04 +01:00
|
|
|
for (j = 0; j < SLANG_CBUFFER_MAX; j++)
|
2018-01-31 01:08:36 +01:00
|
|
|
{
|
|
|
|
D3D11Buffer buffer = d3d11->pass[i].buffers[j];
|
|
|
|
cbuffer_sem_t* buffer_sem = &d3d11->pass[i].semantics.cbuffers[j];
|
|
|
|
|
|
|
|
if (buffer_sem->stage_mask && buffer_sem->uniforms)
|
|
|
|
{
|
|
|
|
D3D11_MAPPED_SUBRESOURCE res;
|
|
|
|
uniform_sem_t* uniform = buffer_sem->uniforms;
|
|
|
|
|
2018-02-03 13:29:00 +01:00
|
|
|
D3D11MapBuffer(context, buffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &res);
|
2018-01-31 12:00:39 +01:00
|
|
|
while (uniform->size)
|
2018-01-31 01:08:36 +01:00
|
|
|
{
|
2018-01-31 15:55:59 +01:00
|
|
|
if (uniform->data)
|
2018-01-31 12:00:39 +01:00
|
|
|
memcpy((uint8_t*)res.pData + uniform->offset, uniform->data, uniform->size);
|
2018-01-31 01:08:36 +01:00
|
|
|
uniform++;
|
|
|
|
}
|
2018-02-03 13:29:00 +01:00
|
|
|
D3D11UnmapBuffer(context, buffer, 0);
|
2018-01-31 01:08:36 +01:00
|
|
|
|
|
|
|
if (buffer_sem->stage_mask & SLANG_STAGE_VERTEX_MASK)
|
2018-02-03 13:29:00 +01:00
|
|
|
D3D11SetVShaderConstantBuffers(context, buffer_sem->binding, 1, &buffer);
|
2018-01-31 01:08:36 +01:00
|
|
|
|
|
|
|
if (buffer_sem->stage_mask & SLANG_STAGE_FRAGMENT_MASK)
|
2018-02-03 13:29:00 +01:00
|
|
|
D3D11SetPShaderConstantBuffers(context, buffer_sem->binding, 1, &buffer);
|
2018-01-31 01:08:36 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-03 13:29:00 +01:00
|
|
|
{
|
|
|
|
D3D11RenderTargetView null_rt = NULL;
|
|
|
|
D3D11SetRenderTargets(context, 1, &null_rt, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
D3D11ShaderResourceView textures[SLANG_NUM_BINDINGS] = { NULL };
|
|
|
|
D3D11SamplerState samplers[SLANG_NUM_BINDINGS] = { NULL };
|
|
|
|
|
2020-08-19 11:26:30 +02:00
|
|
|
texture_sem_t *texture_sem = d3d11->pass[i].semantics.textures;
|
2018-02-03 13:29:00 +01:00
|
|
|
while (texture_sem->stage_mask)
|
|
|
|
{
|
|
|
|
int binding = texture_sem->binding;
|
|
|
|
textures[binding] = *(D3D11ShaderResourceView*)texture_sem->texture_data;
|
2018-02-11 22:56:37 +01:00
|
|
|
samplers[binding] = d3d11->samplers[texture_sem->filter][texture_sem->wrap];
|
2018-02-03 13:29:00 +01:00
|
|
|
texture_sem++;
|
|
|
|
}
|
2018-01-31 01:08:36 +01:00
|
|
|
|
2020-10-01 00:05:49 +10:00
|
|
|
D3D11SetPShaderResources(context, 0, SLANG_NUM_BINDINGS, textures);
|
2018-02-03 13:29:00 +01:00
|
|
|
D3D11SetPShaderSamplers(context, 0, SLANG_NUM_BINDINGS, samplers);
|
|
|
|
}
|
2018-01-31 01:08:36 +01:00
|
|
|
|
2020-08-19 11:26:30 +02:00
|
|
|
if (!d3d11->pass[i].rt.handle)
|
2018-01-31 01:08:36 +01:00
|
|
|
{
|
|
|
|
texture = NULL;
|
|
|
|
break;
|
|
|
|
}
|
2020-08-19 11:26:30 +02:00
|
|
|
|
|
|
|
D3D11SetRenderTargets(context, 1, &d3d11->pass[i].rt.rt_view, NULL);
|
|
|
|
D3D11SetViewports(context, 1, &d3d11->pass[i].viewport);
|
|
|
|
|
|
|
|
D3D11Draw(context, 4, 0);
|
2020-11-15 13:01:55 +01:00
|
|
|
texture = &d3d11->pass[i].rt;
|
2018-01-31 01:08:36 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-03 06:15:25 +02:00
|
|
|
|
|
|
|
#ifdef HAVE_DXGI_HDR
|
|
|
|
if(d3d11->hdr.enable)
|
|
|
|
{
|
|
|
|
D3D11SetRenderTargets(context, 1, &d3d11->back_buffer.rt_view, NULL);
|
|
|
|
D3D11ClearRenderTargetView(context, d3d11->back_buffer.rt_view, d3d11->clearcolor);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
D3D11SetRenderTargets(context, 1, &rtv, NULL);
|
|
|
|
D3D11ClearRenderTargetView(context, rtv, d3d11->clearcolor);
|
|
|
|
}
|
|
|
|
|
2020-10-01 19:18:19 +10:00
|
|
|
D3D11SetViewports(context, 1, &d3d11->frame.viewport);
|
|
|
|
|
2018-01-31 01:08:36 +01:00
|
|
|
if (texture)
|
|
|
|
{
|
2018-02-03 13:29:00 +01:00
|
|
|
d3d11_set_shader(context, &d3d11->shaders[VIDEO_SHADER_STOCK_BLEND]);
|
2020-11-15 13:01:55 +01:00
|
|
|
D3D11SetPShaderResources(context, 0, 1, &texture->view);
|
2018-02-02 17:18:41 +01:00
|
|
|
D3D11SetPShaderSamplers(
|
2018-02-03 13:29:00 +01:00
|
|
|
context, 0, 1, &d3d11->samplers[RARCH_FILTER_UNSPEC][RARCH_WRAP_DEFAULT]);
|
|
|
|
D3D11SetVShaderConstantBuffers(context, 0, 1, &d3d11->frame.ubo);
|
2018-01-31 01:08:36 +01:00
|
|
|
}
|
|
|
|
|
2021-06-23 19:34:06 +02:00
|
|
|
D3D11Draw(context, 4, 0);
|
2020-11-15 13:01:55 +01:00
|
|
|
D3D11SetRasterizerState(context, d3d11->scissor_enabled);
|
|
|
|
D3D11SetScissorRects(d3d11->context, 1, &d3d11->scissor);
|
2018-02-03 13:29:00 +01:00
|
|
|
D3D11SetBlendState(context, d3d11->blend_enable, NULL, D3D11_DEFAULT_SAMPLE_MASK);
|
2018-01-25 15:48:53 +01:00
|
|
|
|
2020-08-19 11:26:30 +02:00
|
|
|
#ifdef HAVE_MENU
|
2018-01-25 15:48:53 +01:00
|
|
|
if (d3d11->menu.enabled && d3d11->menu.texture.handle)
|
2018-01-24 20:51:19 +01:00
|
|
|
{
|
2018-01-25 15:48:53 +01:00
|
|
|
if (d3d11->menu.fullscreen)
|
2018-02-03 13:29:00 +01:00
|
|
|
D3D11SetViewports(context, 1, &d3d11->viewport);
|
2018-01-25 15:48:53 +01:00
|
|
|
|
2018-02-03 13:29:00 +01:00
|
|
|
d3d11_set_shader(context, &d3d11->shaders[VIDEO_SHADER_STOCK_BLEND]);
|
|
|
|
D3D11SetVertexBuffer(context, 0, d3d11->menu.vbo, sizeof(d3d11_vertex_t), 0);
|
|
|
|
D3D11SetVShaderConstantBuffers(context, 0, 1, &d3d11->ubo);
|
|
|
|
d3d11_set_texture_and_sampler(context, 0, &d3d11->menu.texture);
|
|
|
|
D3D11Draw(context, 4, 0);
|
2018-01-25 15:48:53 +01:00
|
|
|
}
|
2020-08-19 11:26:30 +02:00
|
|
|
#endif
|
2018-01-24 20:51:19 +01:00
|
|
|
|
2020-11-15 13:01:55 +01:00
|
|
|
D3D11SetViewports(context, 1, &d3d11->viewport);
|
2018-02-03 13:29:00 +01:00
|
|
|
d3d11_set_shader(context, &d3d11->sprites.shader);
|
|
|
|
D3D11SetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_POINTLIST);
|
|
|
|
D3D11SetVShaderConstantBuffer(context, 0, d3d11->ubo);
|
|
|
|
D3D11SetPShaderConstantBuffer(context, 0, d3d11->ubo);
|
2020-11-15 13:01:55 +01:00
|
|
|
D3D11SetVertexBuffer(context, 0, d3d11->sprites.vbo, sizeof(d3d11_sprite_t), 0);
|
2018-01-25 15:48:53 +01:00
|
|
|
d3d11->sprites.enabled = true;
|
|
|
|
|
2021-12-26 05:56:44 +02:00
|
|
|
#ifdef HAVE_OVERLAY
|
|
|
|
if (d3d11->overlays.enabled && overlay_behind_menu)
|
|
|
|
d3d11_render_overlay(d3d11);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef HAVE_MENU
|
|
|
|
#ifndef HAVE_GFX_WIDGETS
|
|
|
|
if (d3d11->menu.enabled)
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
D3D11SetViewports(context, 1, &d3d11->viewport);
|
|
|
|
D3D11SetVertexBuffer(context, 0, d3d11->sprites.vbo, sizeof(d3d11_sprite_t), 0);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2019-04-11 02:21:45 +02:00
|
|
|
#ifdef HAVE_MENU
|
|
|
|
if (d3d11->menu.enabled)
|
2020-05-19 16:20:43 +02:00
|
|
|
menu_driver_frame(menu_is_alive, video_info);
|
2019-01-06 17:04:28 +01:00
|
|
|
else
|
|
|
|
#endif
|
2020-03-09 16:24:20 +01:00
|
|
|
if (statistics_show)
|
2018-03-23 17:43:49 +01:00
|
|
|
{
|
|
|
|
if (osd_params)
|
|
|
|
{
|
|
|
|
D3D11SetViewports(context, 1, &d3d11->viewport);
|
|
|
|
D3D11SetBlendState(d3d11->context, d3d11->blend_enable, NULL, D3D11_DEFAULT_SAMPLE_MASK);
|
|
|
|
D3D11SetVertexBuffer(context, 0, d3d11->sprites.vbo, sizeof(d3d11_sprite_t), 0);
|
2020-01-04 16:24:14 +01:00
|
|
|
font_driver_render_msg(d3d11,
|
2020-03-10 03:24:59 +01:00
|
|
|
stat_text,
|
2020-03-09 16:24:20 +01:00
|
|
|
(const struct font_params*)osd_params, NULL);
|
2018-03-23 17:43:49 +01:00
|
|
|
}
|
|
|
|
}
|
2018-02-12 01:19:43 +01:00
|
|
|
|
|
|
|
#ifdef HAVE_OVERLAY
|
2021-12-26 05:56:44 +02:00
|
|
|
if (d3d11->overlays.enabled && !overlay_behind_menu)
|
|
|
|
d3d11_render_overlay(d3d11);
|
2018-02-12 01:19:43 +01:00
|
|
|
#endif
|
2018-01-25 15:48:53 +01:00
|
|
|
|
2020-02-17 21:28:42 +01:00
|
|
|
#ifdef HAVE_GFX_WIDGETS
|
2020-08-03 16:33:54 +02:00
|
|
|
if (widgets_active)
|
2020-11-15 13:01:55 +01:00
|
|
|
{
|
|
|
|
D3D11SetViewports(context, 1, &d3d11->viewport);
|
2020-06-08 05:45:15 +02:00
|
|
|
gfx_widgets_frame(video_info);
|
2020-11-15 13:01:55 +01:00
|
|
|
}
|
2019-02-07 00:43:36 +01:00
|
|
|
#endif
|
|
|
|
|
2018-01-25 15:48:53 +01:00
|
|
|
if (msg && *msg)
|
|
|
|
{
|
2018-02-12 01:19:43 +01:00
|
|
|
D3D11SetViewports(context, 1, &d3d11->viewport);
|
|
|
|
D3D11SetBlendState(d3d11->context, d3d11->blend_enable, NULL, D3D11_DEFAULT_SAMPLE_MASK);
|
|
|
|
D3D11SetVertexBuffer(context, 0, d3d11->sprites.vbo, sizeof(d3d11_sprite_t), 0);
|
2020-03-10 03:24:59 +01:00
|
|
|
font_driver_render_msg(d3d11, msg, NULL, NULL);
|
2018-01-24 20:51:19 +01:00
|
|
|
}
|
2018-01-25 15:48:53 +01:00
|
|
|
d3d11->sprites.enabled = false;
|
2018-01-21 04:10:45 +01:00
|
|
|
|
2021-06-07 12:03:58 +02:00
|
|
|
#if defined(_WIN32) && !defined(__WINRT__)
|
2021-06-04 04:30:17 +03:00
|
|
|
win32_update_title();
|
2021-06-07 12:03:58 +02:00
|
|
|
#endif
|
2021-09-03 06:15:25 +02:00
|
|
|
|
|
|
|
#ifdef HAVE_DXGI_HDR
|
|
|
|
/* Copy over back buffer to swap chain render targets */
|
|
|
|
if(d3d11->hdr.enable)
|
|
|
|
{
|
2021-09-04 21:40:37 +02:00
|
|
|
ID3D11ShaderResourceView* nullSRV[1] = {NULL};
|
2021-09-03 06:15:25 +02:00
|
|
|
D3D11SetRenderTargets(context, 1, &rtv, NULL);
|
|
|
|
D3D11ClearRenderTargetView(context, rtv,
|
|
|
|
d3d11->clearcolor);
|
|
|
|
D3D11SetViewports(context, 1,
|
|
|
|
&d3d11->viewport);
|
|
|
|
D3D11SetScissorRects(context, 1,
|
|
|
|
&d3d11->scissor);
|
|
|
|
|
|
|
|
d3d11_set_shader(context,
|
|
|
|
&d3d11->shaders[VIDEO_SHADER_STOCK_HDR]);
|
|
|
|
D3D11SetVShaderConstantBuffer(context, 0,
|
|
|
|
d3d11->hdr.ubo);
|
|
|
|
D3D11SetPShaderResources(context, 0, 1,
|
|
|
|
&d3d11->back_buffer.view);
|
|
|
|
D3D11SetPShaderSamplers(context, 0, 1,
|
|
|
|
&d3d11->samplers[RARCH_FILTER_UNSPEC][RARCH_WRAP_DEFAULT]);
|
|
|
|
D3D11SetPShaderConstantBuffer(context, 0, d3d11->hdr.ubo);
|
|
|
|
D3D11SetVertexBuffer(context, 0, d3d11->frame.vbo,
|
|
|
|
sizeof(d3d11_vertex_t), 0);
|
|
|
|
|
|
|
|
D3D11SetRasterizerState(context, d3d11->scissor_disabled);
|
|
|
|
D3D11SetBlendState(context, d3d11->blend_disable, NULL,
|
|
|
|
D3D11_DEFAULT_SAMPLE_MASK);
|
|
|
|
D3D11SetPrimitiveTopology(context,
|
|
|
|
D3D_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
|
|
|
|
|
|
|
|
D3D11Draw(context, 4, 0);
|
2021-09-04 20:13:24 +01:00
|
|
|
|
|
|
|
D3D11SetPShaderResources(context, 0, 1, nullSRV);
|
2021-09-13 15:54:50 +01:00
|
|
|
D3D11SetRasterizerState(context, d3d11->scissor_enabled);
|
|
|
|
D3D11SetBlendState(d3d11->context, d3d11->blend_enable, NULL, D3D11_DEFAULT_SAMPLE_MASK);
|
|
|
|
D3D11SetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_POINTLIST);
|
2021-09-03 06:15:25 +02:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2022-01-21 05:35:22 +02:00
|
|
|
DXGIPresent(d3d11->swapChain, d3d11->swap_interval, present_flags);
|
2020-12-17 14:39:58 +01:00
|
|
|
Release(rtv);
|
2018-01-22 07:35:36 +01:00
|
|
|
|
2018-01-21 04:10:45 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-02-16 22:26:07 +01:00
|
|
|
static void d3d11_gfx_set_nonblock_state(void* data,
|
|
|
|
bool toggle,
|
|
|
|
bool adaptive_vsync_enabled,
|
|
|
|
unsigned swap_interval)
|
2018-01-21 04:10:45 +01:00
|
|
|
{
|
|
|
|
d3d11_video_t* d3d11 = (d3d11_video_t*)data;
|
2018-01-22 07:35:36 +01:00
|
|
|
|
|
|
|
if (!d3d11)
|
|
|
|
return;
|
|
|
|
|
2022-01-21 05:35:22 +02:00
|
|
|
d3d11->vsync = !toggle;
|
|
|
|
d3d11->swap_interval = (!toggle) ? swap_interval : 0;
|
2018-01-21 04:10:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static bool d3d11_gfx_alive(void* data)
|
|
|
|
{
|
2018-01-24 15:00:32 +01:00
|
|
|
bool quit;
|
2018-01-23 20:27:03 +01:00
|
|
|
d3d11_video_t* d3d11 = (d3d11_video_t*)data;
|
2018-01-22 07:35:36 +01:00
|
|
|
|
2020-07-18 17:09:07 +02:00
|
|
|
win32_check_window(NULL,
|
|
|
|
&quit,
|
|
|
|
&d3d11->resize_chain,
|
|
|
|
&d3d11->vp.full_width,
|
|
|
|
&d3d11->vp.full_height);
|
|
|
|
|
|
|
|
if ( d3d11->resize_chain
|
|
|
|
&& d3d11->vp.full_width != 0
|
|
|
|
&& d3d11->vp.full_height != 0)
|
2020-01-31 03:47:50 +01:00
|
|
|
video_driver_set_size(d3d11->vp.full_width, d3d11->vp.full_height);
|
2018-01-21 23:46:50 +01:00
|
|
|
|
|
|
|
return !quit;
|
2018-01-21 04:10:45 +01:00
|
|
|
}
|
|
|
|
|
2020-07-27 13:16:14 +02:00
|
|
|
static bool d3d11_gfx_suppress_screensaver(void* data, bool enable) { return false; }
|
|
|
|
static bool d3d11_gfx_has_windowed(void* data) { return true; }
|
2018-01-21 04:10:45 +01:00
|
|
|
|
2018-01-31 01:08:36 +01:00
|
|
|
static struct video_shader* d3d11_gfx_get_current_shader(void* data)
|
2018-01-21 04:10:45 +01:00
|
|
|
{
|
2018-01-31 01:08:36 +01:00
|
|
|
d3d11_video_t* d3d11 = (d3d11_video_t*)data;
|
2018-01-21 04:10:45 +01:00
|
|
|
|
2018-01-31 01:08:36 +01:00
|
|
|
if (!d3d11)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return d3d11->shader_preset;
|
2018-01-21 04:10:45 +01:00
|
|
|
}
|
|
|
|
|
2018-01-23 18:04:55 +01:00
|
|
|
static void d3d11_gfx_viewport_info(void* data, struct video_viewport* vp)
|
2018-01-21 04:10:45 +01:00
|
|
|
{
|
2018-01-24 15:00:32 +01:00
|
|
|
d3d11_video_t* d3d11 = (d3d11_video_t*)data;
|
|
|
|
|
|
|
|
*vp = d3d11->vp;
|
2018-01-21 04:10:45 +01:00
|
|
|
}
|
|
|
|
|
2018-01-23 18:04:55 +01:00
|
|
|
static void d3d11_set_menu_texture_frame(
|
|
|
|
void* data, const void* frame, bool rgb32, unsigned width, unsigned height, float alpha)
|
2018-01-21 04:10:45 +01:00
|
|
|
{
|
2018-03-30 15:50:11 +02:00
|
|
|
d3d11_video_t* d3d11 = (d3d11_video_t*)data;
|
|
|
|
settings_t* settings = config_get_ptr();
|
2020-02-18 14:51:40 +01:00
|
|
|
bool menu_linear_filter = settings->bools.menu_linear_filter;
|
2019-02-03 15:49:35 -08:00
|
|
|
DXGI_FORMAT format = rgb32 ? DXGI_FORMAT_B8G8R8A8_UNORM :
|
2018-03-30 15:50:11 +02:00
|
|
|
(DXGI_FORMAT)DXGI_FORMAT_EX_A4R4G4B4_UNORM;
|
2018-01-21 04:10:45 +01:00
|
|
|
|
2018-03-30 15:50:11 +02:00
|
|
|
if (
|
2019-02-03 15:49:35 -08:00
|
|
|
d3d11->menu.texture.desc.Width != width ||
|
2018-03-30 15:50:11 +02:00
|
|
|
d3d11->menu.texture.desc.Height != height)
|
2018-01-21 04:10:45 +01:00
|
|
|
{
|
2018-02-01 11:21:51 +01:00
|
|
|
d3d11->menu.texture.desc.Format = format;
|
2018-01-23 18:04:55 +01:00
|
|
|
d3d11->menu.texture.desc.Width = width;
|
|
|
|
d3d11->menu.texture.desc.Height = height;
|
|
|
|
d3d11_init_texture(d3d11->device, &d3d11->menu.texture);
|
2018-01-21 04:10:45 +01:00
|
|
|
}
|
|
|
|
|
2018-03-30 15:50:11 +02:00
|
|
|
d3d11_update_texture(d3d11->context, width, height, 0,
|
|
|
|
format, frame, &d3d11->menu.texture);
|
2018-02-02 17:18:41 +01:00
|
|
|
d3d11->menu.texture.sampler = d3d11->samplers
|
2020-02-18 14:51:40 +01:00
|
|
|
[menu_linear_filter
|
|
|
|
? RARCH_FILTER_LINEAR
|
2018-03-30 15:50:11 +02:00
|
|
|
: RARCH_FILTER_NEAREST][RARCH_WRAP_DEFAULT];
|
2018-01-21 04:10:45 +01:00
|
|
|
}
|
2018-02-01 12:31:24 +01:00
|
|
|
|
2018-01-23 18:04:55 +01:00
|
|
|
static void d3d11_set_menu_texture_enable(void* data, bool state, bool full_screen)
|
2018-01-21 04:10:45 +01:00
|
|
|
{
|
|
|
|
d3d11_video_t* d3d11 = (d3d11_video_t*)data;
|
|
|
|
|
2018-01-22 07:35:36 +01:00
|
|
|
if (!d3d11)
|
|
|
|
return;
|
|
|
|
|
2018-01-23 18:04:55 +01:00
|
|
|
d3d11->menu.enabled = state;
|
|
|
|
d3d11->menu.fullscreen = full_screen;
|
2018-01-21 04:10:45 +01:00
|
|
|
}
|
|
|
|
|
2018-01-24 15:00:32 +01:00
|
|
|
static void d3d11_gfx_set_aspect_ratio(void* data, unsigned aspect_ratio_idx)
|
|
|
|
{
|
|
|
|
d3d11_video_t* d3d11 = (d3d11_video_t*)data;
|
|
|
|
|
|
|
|
if (!d3d11)
|
|
|
|
return;
|
|
|
|
|
|
|
|
d3d11->keep_aspect = true;
|
|
|
|
d3d11->resize_viewport = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void d3d11_gfx_apply_state_changes(void* data)
|
|
|
|
{
|
|
|
|
d3d11_video_t* d3d11 = (d3d11_video_t*)data;
|
|
|
|
|
|
|
|
if (d3d11)
|
|
|
|
d3d11->resize_viewport = true;
|
|
|
|
}
|
|
|
|
|
2018-01-24 20:51:19 +01:00
|
|
|
static void d3d11_gfx_set_osd_msg(
|
2020-03-10 03:24:59 +01:00
|
|
|
void* data,
|
|
|
|
const char* msg,
|
|
|
|
const void* params,
|
|
|
|
void* font)
|
2018-01-24 20:51:19 +01:00
|
|
|
{
|
|
|
|
d3d11_video_t* d3d11 = (d3d11_video_t*)data;
|
|
|
|
|
|
|
|
if (d3d11)
|
|
|
|
if (d3d11->sprites.enabled)
|
2020-03-10 03:24:59 +01:00
|
|
|
font_driver_render_msg(d3d11,
|
|
|
|
msg,
|
|
|
|
(const struct font_params*)params, font);
|
2018-01-24 20:51:19 +01:00
|
|
|
}
|
2018-02-12 01:19:43 +01:00
|
|
|
|
2018-01-25 00:20:06 +01:00
|
|
|
static uintptr_t d3d11_gfx_load_texture(
|
|
|
|
void* video_data, void* data, bool threaded, enum texture_filter_type filter_type)
|
|
|
|
{
|
2018-01-31 01:08:36 +01:00
|
|
|
d3d11_texture_t* texture = NULL;
|
|
|
|
d3d11_video_t* d3d11 = (d3d11_video_t*)video_data;
|
|
|
|
struct texture_image* image = (struct texture_image*)data;
|
2018-01-25 00:20:06 +01:00
|
|
|
|
|
|
|
if (!d3d11)
|
|
|
|
return 0;
|
|
|
|
|
2018-02-04 20:03:27 +01:00
|
|
|
texture = (d3d11_texture_t*)calloc(1, sizeof(*texture));
|
2018-02-03 15:16:04 +01:00
|
|
|
|
|
|
|
if (!texture)
|
|
|
|
return 0;
|
2018-01-25 00:20:06 +01:00
|
|
|
|
2018-01-25 09:48:07 +01:00
|
|
|
switch (filter_type)
|
2018-01-25 04:57:49 +01:00
|
|
|
{
|
2018-01-25 09:48:07 +01:00
|
|
|
case TEXTURE_FILTER_MIPMAP_LINEAR:
|
2021-05-16 20:44:31 +02:00
|
|
|
#ifndef __WINRT__
|
2018-01-25 09:48:07 +01:00
|
|
|
texture->desc.MiscFlags = D3D11_RESOURCE_MISC_GENERATE_MIPS;
|
2021-04-20 10:29:17 +02:00
|
|
|
#endif
|
2018-01-25 09:48:07 +01:00
|
|
|
/* fallthrough */
|
|
|
|
case TEXTURE_FILTER_LINEAR:
|
2018-02-08 17:11:24 +01:00
|
|
|
texture->sampler = d3d11->samplers[RARCH_FILTER_LINEAR][RARCH_WRAP_EDGE];
|
2018-01-25 09:48:07 +01:00
|
|
|
break;
|
|
|
|
case TEXTURE_FILTER_MIPMAP_NEAREST:
|
2021-05-16 20:44:31 +02:00
|
|
|
#ifndef __WINRT__
|
2018-01-25 09:48:07 +01:00
|
|
|
texture->desc.MiscFlags = D3D11_RESOURCE_MISC_GENERATE_MIPS;
|
2021-04-20 10:29:17 +02:00
|
|
|
#endif
|
2018-01-25 09:48:07 +01:00
|
|
|
/* fallthrough */
|
|
|
|
case TEXTURE_FILTER_NEAREST:
|
2018-02-08 17:11:24 +01:00
|
|
|
texture->sampler = d3d11->samplers[RARCH_FILTER_NEAREST][RARCH_WRAP_EDGE];
|
2018-01-25 09:48:07 +01:00
|
|
|
break;
|
2018-01-25 04:57:49 +01:00
|
|
|
}
|
|
|
|
|
2018-01-25 09:48:07 +01:00
|
|
|
texture->desc.Width = image->width;
|
|
|
|
texture->desc.Height = image->height;
|
2018-02-01 11:21:51 +01:00
|
|
|
texture->desc.Format = DXGI_FORMAT_B8G8R8A8_UNORM;
|
2018-01-25 00:20:06 +01:00
|
|
|
|
|
|
|
d3d11_init_texture(d3d11->device, texture);
|
|
|
|
|
|
|
|
d3d11_update_texture(
|
2018-02-03 13:29:00 +01:00
|
|
|
d3d11->context, image->width, image->height, 0, DXGI_FORMAT_B8G8R8A8_UNORM, image->pixels,
|
2018-01-25 00:20:06 +01:00
|
|
|
texture);
|
|
|
|
|
|
|
|
return (uintptr_t)texture;
|
|
|
|
}
|
2020-07-27 10:15:28 +02:00
|
|
|
static void d3d11_gfx_unload_texture(void* data,
|
|
|
|
bool threaded, uintptr_t handle)
|
2018-01-25 00:20:06 +01:00
|
|
|
{
|
|
|
|
d3d11_texture_t* texture = (d3d11_texture_t*)handle;
|
|
|
|
|
|
|
|
if (!texture)
|
|
|
|
return;
|
|
|
|
|
|
|
|
Release(texture->view);
|
|
|
|
Release(texture->staging);
|
|
|
|
Release(texture->handle);
|
|
|
|
free(texture);
|
|
|
|
}
|
|
|
|
|
2020-07-27 13:16:14 +02:00
|
|
|
static bool d3d11_get_hw_render_interface(
|
|
|
|
void* data, const struct retro_hw_render_interface** iface)
|
2018-03-25 23:14:14 +01:00
|
|
|
{
|
|
|
|
d3d11_video_t* d3d11 = (d3d11_video_t*)data;
|
2020-07-27 13:16:14 +02:00
|
|
|
*iface = (const struct retro_hw_render_interface*)
|
|
|
|
&d3d11->hw.iface;
|
2018-03-25 23:14:14 +01:00
|
|
|
return d3d11->hw.enable;
|
|
|
|
}
|
|
|
|
|
2020-08-08 19:12:01 +02:00
|
|
|
#ifndef __WINRT__
|
2020-07-25 11:47:49 +02:00
|
|
|
static void d3d11_get_video_output_size(void *data,
|
2021-09-07 20:25:22 +02:00
|
|
|
unsigned *width, unsigned *height, char *desc, size_t desc_len)
|
2020-07-25 11:47:49 +02:00
|
|
|
{
|
2021-09-07 20:25:22 +02:00
|
|
|
win32_get_video_output_size(width, height, desc, desc_len);
|
2020-07-25 11:47:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void d3d11_get_video_output_prev(void *data)
|
|
|
|
{
|
|
|
|
unsigned width = 0;
|
|
|
|
unsigned height = 0;
|
|
|
|
win32_get_video_output_prev(&width, &height);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void d3d11_get_video_output_next(void *data)
|
|
|
|
{
|
|
|
|
unsigned width = 0;
|
|
|
|
unsigned height = 0;
|
|
|
|
win32_get_video_output_next(&width, &height);
|
|
|
|
}
|
2020-08-08 18:17:40 +02:00
|
|
|
#endif
|
2020-07-25 11:47:49 +02:00
|
|
|
|
2018-01-23 18:04:55 +01:00
|
|
|
static const video_poke_interface_t d3d11_poke_interface = {
|
2018-04-24 15:14:06 +02:00
|
|
|
d3d11_get_flags,
|
2018-01-25 00:20:06 +01:00
|
|
|
d3d11_gfx_load_texture,
|
|
|
|
d3d11_gfx_unload_texture,
|
2020-08-02 23:44:28 +02:00
|
|
|
NULL, /* set_video_mode */
|
2018-12-28 12:41:38 +01:00
|
|
|
#ifndef __WINRT__
|
2018-04-15 19:33:38 -05:00
|
|
|
win32_get_refresh_rate,
|
2018-12-28 12:41:38 +01:00
|
|
|
#else
|
|
|
|
/* UWP does not expose this information easily */
|
|
|
|
NULL,
|
|
|
|
#endif
|
2018-01-24 15:00:32 +01:00
|
|
|
d3d11_set_filtering,
|
2020-08-08 18:17:40 +02:00
|
|
|
#ifdef __WINRT__
|
|
|
|
NULL, /* get_video_output_size */
|
|
|
|
NULL, /* get_video_output_prev */
|
|
|
|
NULL, /* get_video_output_next */
|
|
|
|
#else
|
2020-07-25 11:47:49 +02:00
|
|
|
d3d11_get_video_output_size,
|
|
|
|
d3d11_get_video_output_prev,
|
|
|
|
d3d11_get_video_output_next,
|
2020-08-08 18:17:40 +02:00
|
|
|
#endif
|
2018-01-24 15:00:32 +01:00
|
|
|
NULL, /* get_current_framebuffer */
|
|
|
|
NULL, /* get_proc_address */
|
|
|
|
d3d11_gfx_set_aspect_ratio,
|
|
|
|
d3d11_gfx_apply_state_changes,
|
|
|
|
d3d11_set_menu_texture_frame,
|
|
|
|
d3d11_set_menu_texture_enable,
|
2018-01-24 20:51:19 +01:00
|
|
|
d3d11_gfx_set_osd_msg,
|
2020-01-04 15:40:02 +01:00
|
|
|
win32_show_cursor,
|
2018-01-24 15:00:32 +01:00
|
|
|
NULL, /* grab_mouse_toggle */
|
2018-01-31 01:08:36 +01:00
|
|
|
d3d11_gfx_get_current_shader,
|
2018-01-24 15:00:32 +01:00
|
|
|
NULL, /* get_current_software_framebuffer */
|
2018-03-25 23:14:14 +01:00
|
|
|
d3d11_get_hw_render_interface,
|
2021-09-03 06:15:25 +02:00
|
|
|
#ifdef HAVE_DXGI_HDR
|
|
|
|
d3d11_set_hdr_max_nits,
|
|
|
|
d3d11_set_hdr_paper_white_nits,
|
|
|
|
d3d11_set_hdr_contrast,
|
|
|
|
d3d11_set_hdr_expand_gamut
|
|
|
|
#else
|
|
|
|
NULL, /* set_hdr_max_nits */
|
|
|
|
NULL, /* set_hdr_paper_white_nits */
|
|
|
|
NULL, /* set_hdr_contrast */
|
|
|
|
NULL /* set_hdr_expand_gamut */
|
|
|
|
#endif
|
2018-01-21 04:10:45 +01:00
|
|
|
};
|
|
|
|
|
2020-07-27 13:16:14 +02:00
|
|
|
static void d3d11_gfx_get_poke_interface(void* data,
|
|
|
|
const video_poke_interface_t** iface)
|
2018-01-21 04:10:45 +01:00
|
|
|
{
|
|
|
|
*iface = &d3d11_poke_interface;
|
|
|
|
}
|
|
|
|
|
2020-02-17 21:28:42 +01:00
|
|
|
#if defined(HAVE_GFX_WIDGETS)
|
2020-07-27 13:16:14 +02:00
|
|
|
static bool d3d11_gfx_widgets_enabled(void *data) { return true; }
|
2019-02-07 00:43:36 +01:00
|
|
|
#endif
|
|
|
|
|
2018-01-23 18:04:55 +01:00
|
|
|
video_driver_t video_d3d11 = {
|
2018-01-21 04:10:45 +01:00
|
|
|
d3d11_gfx_init,
|
|
|
|
d3d11_gfx_frame,
|
|
|
|
d3d11_gfx_set_nonblock_state,
|
|
|
|
d3d11_gfx_alive,
|
2020-01-04 15:49:23 +01:00
|
|
|
win32_has_focus,
|
2018-01-21 04:10:45 +01:00
|
|
|
d3d11_gfx_suppress_screensaver,
|
|
|
|
d3d11_gfx_has_windowed,
|
|
|
|
d3d11_gfx_set_shader,
|
|
|
|
d3d11_gfx_free,
|
|
|
|
"d3d11",
|
|
|
|
NULL, /* set_viewport */
|
|
|
|
d3d11_gfx_set_rotation,
|
|
|
|
d3d11_gfx_viewport_info,
|
2019-05-22 07:07:33 +02:00
|
|
|
NULL, /* read_viewport */
|
2018-01-21 04:10:45 +01:00
|
|
|
NULL, /* read_frame_raw */
|
|
|
|
|
|
|
|
#ifdef HAVE_OVERLAY
|
2018-02-12 01:19:43 +01:00
|
|
|
d3d11_get_overlay_interface,
|
2019-04-01 04:00:58 +01:00
|
|
|
#endif
|
|
|
|
#ifdef HAVE_VIDEO_LAYOUT
|
|
|
|
NULL,
|
2018-01-21 04:10:45 +01:00
|
|
|
#endif
|
|
|
|
d3d11_gfx_get_poke_interface,
|
2019-02-07 00:43:36 +01:00
|
|
|
NULL, /* d3d11_wrap_type_to_enum */
|
2020-02-17 21:28:42 +01:00
|
|
|
#if defined(HAVE_GFX_WIDGETS)
|
2020-02-17 01:43:40 +01:00
|
|
|
d3d11_gfx_widgets_enabled
|
2019-02-07 00:43:36 +01:00
|
|
|
#endif
|
2018-01-21 04:10:45 +01:00
|
|
|
};
|