add experimental D3D11 hwrender support.

This commit is contained in:
aliaspider 2018-03-25 23:14:14 +01:00
parent 88d1c1fdca
commit 3d96cacd71
5 changed files with 138 additions and 9 deletions

View File

@ -885,6 +885,23 @@ static bool dynamic_request_hw_context(enum retro_hw_context_type type,
break;
#endif
case RETRO_HW_CONTEXT_DIRECT3D:
switch(major)
{
#ifdef HAVE_D3D9
case 9:
#endif
#ifdef HAVE_D3D11
case 11:
#endif
RARCH_LOG("Requesting D3D%i context.\n", major);
break;
default:
goto unknown;
}
break;
unknown:
default:
RARCH_LOG("Requesting unknown context.\n");
return false;
@ -912,6 +929,10 @@ static bool dynamic_verify_hw_context(enum retro_hw_context_type type,
if (!string_is_equal(video_ident, "gl"))
return false;
break;
case RETRO_HW_CONTEXT_DIRECT3D:
if (!(string_is_equal(video_ident, "d3d11") && major == 11))
return false;
break;
default:
break;
}

View File

@ -2420,6 +2420,7 @@ D3D11UnmapBuffer(D3D11DeviceContext device_context, D3D11Buffer buffer, UINT sub
#include <boolean.h>
#include <retro_math.h>
#include <gfx/math/matrix_4x4.h>
#include <libretro_d3d.h>
#include "../video_driver.h"
#include "../drivers_shader/slang_process.h"
@ -2518,7 +2519,13 @@ typedef struct
bool init_history;
d3d11_shader_t shaders[GFX_MAX_SHADERS];
struct
struct
{
bool enable;
struct retro_hw_render_interface_d3d11 iface;
} hw;
struct
{
d3d11_shader_t shader;
d3d11_shader_t shader_font;

View File

@ -900,6 +900,19 @@ d3d11_gfx_init(const video_info_t* video, const input_driver_t** input, void** i
d3d11_gfx_set_shader(d3d11, RARCH_SHADER_SLANG, settings->paths.path_shader);
}
if (video_driver_get_hw_context()->context_type == RETRO_HW_CONTEXT_DIRECT3D &&
video_driver_get_hw_context()->version_major == 11)
{
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;
}
return d3d11;
error:
@ -1076,6 +1089,12 @@ static bool d3d11_gfx_frame(
D3D11SetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
if (d3d11->hw.enable)
{
D3D11SetRenderTargets(context, 1, &d3d11->renderTargetView, NULL);
D3D11SetState(context, d3d11->state);
}
if (frame && width && height)
{
if (d3d11->shader_preset)
@ -1125,8 +1144,9 @@ static bool d3d11_gfx_frame(
if (d3d11->resize_render_targets)
d3d11_init_render_targets(d3d11, width, height);
d3d11_update_texture(
context, width, height, pitch, d3d11->format, frame, &d3d11->frame.texture[0]);
if (frame != RETRO_HW_FRAME_BUFFER_VALID)
d3d11_update_texture(
context, width, height, pitch, d3d11->format, frame, &d3d11->frame.texture[0]);
}
D3D11SetVertexBuffer(context, 0, d3d11->frame.vbo, sizeof(d3d11_vertex_t), 0);
@ -1203,7 +1223,11 @@ static bool d3d11_gfx_frame(
texture_sem++;
}
D3D11SetPShaderResources(context, 0, SLANG_NUM_BINDINGS, textures);
if (d3d11->hw.enable && (i == 0))
D3D11SetPShaderResources(context, 1, SLANG_NUM_BINDINGS - 1, textures + 1);
else
D3D11SetPShaderResources(context, 0, SLANG_NUM_BINDINGS, textures);
D3D11SetPShaderSamplers(context, 0, SLANG_NUM_BINDINGS, samplers);
}
@ -1230,7 +1254,8 @@ static bool d3d11_gfx_frame(
if (texture)
{
d3d11_set_shader(context, &d3d11->shaders[VIDEO_SHADER_STOCK_BLEND]);
D3D11SetPShaderResources(context, 0, 1, &texture->view);
if (!d3d11->hw.enable || d3d11->shader_preset)
D3D11SetPShaderResources(context, 0, 1, &texture->view);
D3D11SetPShaderSamplers(
context, 0, 1, &d3d11->samplers[RARCH_FILTER_UNSPEC][RARCH_WRAP_DEFAULT]);
D3D11SetVShaderConstantBuffers(context, 0, 1, &d3d11->frame.ubo);
@ -1507,6 +1532,14 @@ static void d3d11_gfx_unload_texture(void* data, uintptr_t handle)
free(texture);
}
static bool
d3d11_get_hw_render_interface(void* data, const struct retro_hw_render_interface** iface)
{
d3d11_video_t* d3d11 = (d3d11_video_t*)data;
*iface = (const struct retro_hw_render_interface*)&d3d11->hw.iface;
return d3d11->hw.enable;
}
static const video_poke_interface_t d3d11_poke_interface = {
NULL, /* set_coords */
NULL, /* set_mvp */
@ -1528,7 +1561,7 @@ static const video_poke_interface_t d3d11_poke_interface = {
NULL, /* grab_mouse_toggle */
d3d11_gfx_get_current_shader,
NULL, /* get_current_software_framebuffer */
NULL, /* get_hw_render_interface */
d3d11_get_hw_render_interface,
};
static void d3d11_gfx_get_poke_interface(void* data, const video_poke_interface_t** iface)

View File

@ -1088,8 +1088,12 @@ struct retro_vfs_interface_info
enum retro_hw_render_interface_type
{
RETRO_HW_RENDER_INTERFACE_VULKAN = 0,
RETRO_HW_RENDER_INTERFACE_DUMMY = INT_MAX
RETRO_HW_RENDER_INTERFACE_VULKAN = 0,
RETRO_HW_RENDER_INTERFACE_D3D9 = 1,
RETRO_HW_RENDER_INTERFACE_D3D10 = 2,
RETRO_HW_RENDER_INTERFACE_D3D11 = 3,
RETRO_HW_RENDER_INTERFACE_D3D12 = 4,
RETRO_HW_RENDER_INTERFACE_DUMMY = INT_MAX
};
/* Base struct. All retro_hw_render_interface_* types
@ -1103,7 +1107,7 @@ struct retro_hw_render_interface
#define RETRO_ENVIRONMENT_GET_LED_INTERFACE (46 | RETRO_ENVIRONMENT_EXPERIMENTAL)
/* struct retro_led_interface * --
* Gets an interface which is used by a libretro core to set
* Gets an interface which is used by a libretro core to set
* state of LEDs.
*/
@ -1851,6 +1855,10 @@ enum retro_hw_context_type
/* Vulkan, see RETRO_ENVIRONMENT_GET_HW_RENDER_INTERFACE. */
RETRO_HW_CONTEXT_VULKAN = 6,
/* Direct3D, set version_major to select the type of interface
* returned by RETRO_ENVIRONMENT_GET_HW_RENDER_INTERFACE */
RETRO_HW_CONTEXT_DIRECT3D = 7,
RETRO_HW_CONTEXT_DUMMY = INT_MAX
};

View File

@ -0,0 +1,60 @@
/* Copyright (C) 2010-2016 The RetroArch team
*
* ---------------------------------------------------------------------------------------------
* The following license statement only applies to this libretro API header (libretro_vulkan.h)
* ---------------------------------------------------------------------------------------------
*
* Permission is hereby granted, free of charge,
* to any person obtaining a copy of this software and associated documentation files (the
* "Software"),
* to deal in the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or
* substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef LIBRETRO_DIRECT3D_H__
#define LIBRETRO_DIRECT3D_H__
#include "libretro.h"
#ifdef HAVE_D3D11
#include <d3d11.h>
#include <D3Dcompiler.h>
#define RETRO_HW_RENDER_INTERFACE_D3D11_VERSION 1
struct retro_hw_render_interface_d3d11
{
/* Must be set to RETRO_HW_RENDER_INTERFACE_D3D11. */
enum retro_hw_render_interface_type interface_type;
/* Must be set to RETRO_HW_RENDER_INTERFACE_D3D11_VERSION. */
unsigned interface_version;
/* Opaque handle to the d3d11 backend in the frontend
* which must be passed along to all function pointers
* in this interface.
*/
void* handle;
ID3D11Device *device;
ID3D11DeviceContext *context;
D3D_FEATURE_LEVEL featureLevel;
pD3DCompile D3DCompile;
};
#endif
#endif /* LIBRETRO_DIRECT3D_H__ */