RetroArch/gfx/common/d3d11_common.h

335 lines
10 KiB
C
Raw Normal View History

/* RetroArch - A frontend for libretro.
* Copyright (C) 2014-2018 - Ali Bouhlel
*
* 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/>.
*/
#pragma once
#include <retro_inline.h>
#include <lists/string_list.h>
#include "dxgi_common.h"
2018-02-04 20:03:27 +01:00
#ifdef CINTERFACE
#define D3D11_NO_HELPERS
#endif
2018-01-30 19:34:53 +01:00
#include <d3d11.h>
#include <assert.h>
#include <boolean.h>
#include <retro_math.h>
#include <gfx/math/matrix_4x4.h>
#include <libretro_d3d.h>
#include "../drivers_shader/slang_process.h"
#define D3D11_MAX_GPU_COUNT 16
typedef const ID3D11ShaderResourceView* D3D11ShaderResourceViewRef;
typedef const ID3D11SamplerState* D3D11SamplerStateRef;
typedef const ID3D11BlendState* D3D11BlendStateRef;
typedef ID3D11InputLayout* D3D11InputLayout;
typedef ID3D11RasterizerState* D3D11RasterizerState;
typedef ID3D11DepthStencilState* D3D11DepthStencilState;
typedef ID3D11BlendState* D3D11BlendState;
typedef ID3D11PixelShader* D3D11PixelShader;
typedef ID3D11SamplerState* D3D11SamplerState;
typedef ID3D11VertexShader* D3D11VertexShader;
typedef ID3D11DomainShader* D3D11DomainShader;
typedef ID3D11HullShader* D3D11HullShader;
typedef ID3D11ComputeShader* D3D11ComputeShader;
typedef ID3D11GeometryShader* D3D11GeometryShader;
/* auto-generated */
typedef ID3D11Resource* D3D11Resource;
typedef ID3D11Buffer* D3D11Buffer;
typedef ID3D11Texture1D* D3D11Texture1D;
typedef ID3D11Texture2D* D3D11Texture2D;
typedef ID3D11Texture3D* D3D11Texture3D;
typedef ID3D11View* D3D11View;
typedef ID3D11ShaderResourceView* D3D11ShaderResourceView;
typedef ID3D11RenderTargetView* D3D11RenderTargetView;
typedef ID3D11DepthStencilView* D3D11DepthStencilView;
typedef ID3D11UnorderedAccessView* D3D11UnorderedAccessView;
typedef ID3D11Asynchronous* D3D11Asynchronous;
typedef ID3D11Query* D3D11Query;
typedef ID3D11Predicate* D3D11Predicate;
typedef ID3D11Counter* D3D11Counter;
typedef ID3D11ClassInstance* D3D11ClassInstance;
typedef ID3D11ClassLinkage* D3D11ClassLinkage;
typedef ID3D11CommandList* D3D11CommandList;
typedef ID3D11DeviceContext* D3D11DeviceContext;
typedef ID3D11VideoDecoder* D3D11VideoDecoder;
typedef ID3D11VideoProcessorEnumerator* D3D11VideoProcessorEnumerator;
typedef ID3D11VideoProcessor* D3D11VideoProcessor;
typedef ID3D11AuthenticatedChannel* D3D11AuthenticatedChannel;
typedef ID3D11CryptoSession* D3D11CryptoSession;
typedef ID3D11VideoDecoderOutputView* D3D11VideoDecoderOutputView;
typedef ID3D11VideoProcessorInputView* D3D11VideoProcessorInputView;
typedef ID3D11VideoProcessorOutputView* D3D11VideoProcessorOutputView;
typedef ID3D11VideoContext* D3D11VideoContext;
typedef ID3D11VideoDevice* D3D11VideoDevice;
typedef ID3D11Device* D3D11Device;
2021-03-23 21:23:57 +01:00
#ifdef DEBUG
typedef ID3D11Debug* D3D11Debug;
2021-03-23 21:23:57 +01:00
#endif
typedef ID3D11SwitchToRef* D3D11SwitchToRef;
typedef ID3D11TracingDevice* D3D11TracingDevice;
typedef ID3D11InfoQueue* D3D11InfoQueue;
2022-04-24 13:40:38 +02:00
enum d3d11_feature_level_hint
{
D3D11_FEATURE_LEVEL_HINT_DONTCARE,
D3D11_FEATURE_LEVEL_HINT_1_0_CORE,
D3D11_FEATURE_LEVEL_HINT_9_1,
D3D11_FEATURE_LEVEL_HINT_9_2,
D3D11_FEATURE_LEVEL_HINT_9_3,
D3D11_FEATURE_LEVEL_HINT_10_0,
D3D11_FEATURE_LEVEL_HINT_10_1,
D3D11_FEATURE_LEVEL_HINT_11_0,
D3D11_FEATURE_LEVEL_HINT_11_1,
D3D11_FEATURE_LEVEL_HINT_12_0,
D3D11_FEATURE_LEVEL_HINT_12_1,
D3D11_FEATURE_LEVEL_HINT_12_2
};
typedef struct d3d11_vertex_t
{
float position[2];
float texcoord[2];
float color[4];
} d3d11_vertex_t;
typedef struct
{
D3D11Texture2D handle;
D3D11Texture2D staging;
D3D11_TEXTURE2D_DESC desc;
D3D11RenderTargetView rt_view;
D3D11ShaderResourceView view;
D3D11SamplerStateRef sampler;
float4_t size_data;
} d3d11_texture_t;
2018-01-24 20:51:19 +01:00
typedef struct
{
2020-08-14 22:21:05 +02:00
UINT32 colors[4];
2018-01-24 20:51:19 +01:00
struct
{
float x, y, w, h;
} pos;
struct
{
float u, v, w, h;
} coords;
struct
{
float scaling;
float rotation;
2018-01-25 04:57:49 +01:00
} params;
2018-01-24 20:51:19 +01:00
} d3d11_sprite_t;
#ifndef ALIGN
#ifdef _MSC_VER
#define ALIGN(x) __declspec(align(x))
#else
#define ALIGN(x) __attribute__((aligned(x)))
#endif
#endif
2018-01-25 10:40:32 +01:00
typedef struct ALIGN(16)
{
math_matrix_4x4 mvp;
struct
{
float width;
float height;
} OutputSize;
float time;
} d3d11_uniform_t;
typedef struct d3d11_shader_t
2018-01-25 15:48:53 +01:00
{
D3D11VertexShader vs;
D3D11PixelShader ps;
D3D11GeometryShader gs;
D3D11InputLayout layout;
} d3d11_shader_t;
2018-01-25 10:40:32 +01:00
typedef struct
{
unsigned cur_mon_id;
HANDLE frameLatencyWaitableObject;
DXGISwapChain swapChain;
D3D11Device device;
D3D_FEATURE_LEVEL supportedFeatureLevel;
D3D11DeviceContext context;
2020-11-15 13:01:55 +01:00
D3D11RasterizerState scissor_enabled;
D3D11RasterizerState scissor_disabled;
D3D11Buffer ubo;
d3d11_uniform_t ubo_values;
Add HDR support for D3D12 (rebased PR from MajorPainTheCactus) (#12917) * Add HDR support * Attempt to fix Mingw build and Metal builds * (D3D12) Fix relative header includes * Add missing hdr_sm5.hlsl.h * (d3d12_common.c) Some C89 build fixes * Fix MSVC build * - Attempt to fix build on mingw/msys unix with dirty hack - Fix shader compilation of hdr_sm5.hlsl.h on MSVC/Visual Studio - the define was seen as an error and was causing the first pipeline to error out - Make sure we manually set handle of backBuffer to NULL * Moving the release of the texture above the freeing of desc.srv_heap and desc.rtv_heap solves the hard crashes on teardown/setup in RA - it was crashing hard in d3d12_release_texture before * Add HAVE_D3D12_HDR ifdef - needs to be disabled for WinRT for now because of several things that are Windows desktop-specific right now (GetWindowRect) * Add dirty GUID hack - should work for both mingw/msys on Windows/Linux as well as MSVC/Visual Studio (hopefully) * Change HAVE_D3D12_HDR to HAVE_DXGI_HDR * Move away from camelcase named variables * Fix RARCH_ERR logs - they need a newline at the end * d3d12_check_display_hdr_support - make it return a bool on return and set d3d12->hdr.support and d3d12->hdr.enable outside of the function * (DXGI) Remove D3D12 dependencies from dxgi_check_display_hdr_support and move it to dxgi_common.c instead * (DXGI) move d3d12_swapchain_color_space over to dxgi_common.c and rename it dxgi_swapchain_color_space * (DXGI) move d3d12_set_hdr_metadata to dxgi_common.c and rename it dxgi_set_hdr_metadata * (DXGI) dxgi_check_display_hdr_support - better error handling? * Fix typo * Remove video_force_resolution * (D3D12) Address TODO/FIXME * (D3D12) Backport https://github.com/libretro/RetroArch/pull/12916/commits/c1b6c0bff2aa33cde035b43cb31ac7e78ff2a07a - Fixed resource transition for present when HDR is off Fixed cel shader displaying all black as blending was enabled when the hdr shader was being applied - turned off blending during this shader * Move d3d12_hdr_uniform_t to dxgi_common.h and rename it dxgi_hdr_uniform_t * (D3D11) Add HDR support * Add TODO/FIXME notes * Cache hdr_enable in video_frame_info_t * Update comment
2021-09-03 06:15:25 +02:00
#ifdef HAVE_DXGI_HDR
d3d11_texture_t back_buffer;
#endif
D3D11SamplerState samplers[RARCH_FILTER_MAX][RARCH_WRAP_MAX];
D3D11BlendState blend_enable;
D3D11BlendState blend_disable;
D3D11BlendState blend_pipeline;
D3D11Buffer menu_pipeline_vbo;
math_matrix_4x4 mvp, mvp_no_rot;
struct video_viewport vp;
D3D11_VIEWPORT viewport;
2020-11-15 13:01:55 +01:00
D3D11_RECT scissor;
DXGI_FORMAT format;
float clearcolor[4];
unsigned swap_interval;
bool vsync;
bool waitable_swapchains;
bool wait_for_vblank;
bool resize_chain;
bool keep_aspect;
bool resize_viewport;
bool resize_render_targets;
bool init_history;
bool has_flip_model;
bool has_allow_tearing;
d3d11_shader_t shaders[GFX_MAX_SHADERS];
Add HDR support for D3D12 (rebased PR from MajorPainTheCactus) (#12917) * Add HDR support * Attempt to fix Mingw build and Metal builds * (D3D12) Fix relative header includes * Add missing hdr_sm5.hlsl.h * (d3d12_common.c) Some C89 build fixes * Fix MSVC build * - Attempt to fix build on mingw/msys unix with dirty hack - Fix shader compilation of hdr_sm5.hlsl.h on MSVC/Visual Studio - the define was seen as an error and was causing the first pipeline to error out - Make sure we manually set handle of backBuffer to NULL * Moving the release of the texture above the freeing of desc.srv_heap and desc.rtv_heap solves the hard crashes on teardown/setup in RA - it was crashing hard in d3d12_release_texture before * Add HAVE_D3D12_HDR ifdef - needs to be disabled for WinRT for now because of several things that are Windows desktop-specific right now (GetWindowRect) * Add dirty GUID hack - should work for both mingw/msys on Windows/Linux as well as MSVC/Visual Studio (hopefully) * Change HAVE_D3D12_HDR to HAVE_DXGI_HDR * Move away from camelcase named variables * Fix RARCH_ERR logs - they need a newline at the end * d3d12_check_display_hdr_support - make it return a bool on return and set d3d12->hdr.support and d3d12->hdr.enable outside of the function * (DXGI) Remove D3D12 dependencies from dxgi_check_display_hdr_support and move it to dxgi_common.c instead * (DXGI) move d3d12_swapchain_color_space over to dxgi_common.c and rename it dxgi_swapchain_color_space * (DXGI) move d3d12_set_hdr_metadata to dxgi_common.c and rename it dxgi_set_hdr_metadata * (DXGI) dxgi_check_display_hdr_support - better error handling? * Fix typo * Remove video_force_resolution * (D3D12) Address TODO/FIXME * (D3D12) Backport https://github.com/libretro/RetroArch/pull/12916/commits/c1b6c0bff2aa33cde035b43cb31ac7e78ff2a07a - Fixed resource transition for present when HDR is off Fixed cel shader displaying all black as blending was enabled when the hdr shader was being applied - turned off blending during this shader * Move d3d12_hdr_uniform_t to dxgi_common.h and rename it dxgi_hdr_uniform_t * (D3D11) Add HDR support * Add TODO/FIXME notes * Cache hdr_enable in video_frame_info_t * Update comment
2021-09-03 06:15:25 +02:00
#ifdef HAVE_DXGI_HDR
enum dxgi_swapchain_bit_depth
chain_bit_depth;
DXGI_COLOR_SPACE_TYPE chain_color_space;
DXGI_FORMAT chain_formats[DXGI_SWAPCHAIN_BIT_DEPTH_COUNT];
#endif
#ifdef __WINRT__
DXGIFactory2 factory;
#else
2022-09-11 23:14:54 +02:00
DXGIFactory1 factory;
#endif
DXGIAdapter adapter;
struct
{
bool enable;
struct retro_hw_render_interface_d3d11 iface;
} hw;
Add HDR support for D3D12 (rebased PR from MajorPainTheCactus) (#12917) * Add HDR support * Attempt to fix Mingw build and Metal builds * (D3D12) Fix relative header includes * Add missing hdr_sm5.hlsl.h * (d3d12_common.c) Some C89 build fixes * Fix MSVC build * - Attempt to fix build on mingw/msys unix with dirty hack - Fix shader compilation of hdr_sm5.hlsl.h on MSVC/Visual Studio - the define was seen as an error and was causing the first pipeline to error out - Make sure we manually set handle of backBuffer to NULL * Moving the release of the texture above the freeing of desc.srv_heap and desc.rtv_heap solves the hard crashes on teardown/setup in RA - it was crashing hard in d3d12_release_texture before * Add HAVE_D3D12_HDR ifdef - needs to be disabled for WinRT for now because of several things that are Windows desktop-specific right now (GetWindowRect) * Add dirty GUID hack - should work for both mingw/msys on Windows/Linux as well as MSVC/Visual Studio (hopefully) * Change HAVE_D3D12_HDR to HAVE_DXGI_HDR * Move away from camelcase named variables * Fix RARCH_ERR logs - they need a newline at the end * d3d12_check_display_hdr_support - make it return a bool on return and set d3d12->hdr.support and d3d12->hdr.enable outside of the function * (DXGI) Remove D3D12 dependencies from dxgi_check_display_hdr_support and move it to dxgi_common.c instead * (DXGI) move d3d12_swapchain_color_space over to dxgi_common.c and rename it dxgi_swapchain_color_space * (DXGI) move d3d12_set_hdr_metadata to dxgi_common.c and rename it dxgi_set_hdr_metadata * (DXGI) dxgi_check_display_hdr_support - better error handling? * Fix typo * Remove video_force_resolution * (D3D12) Address TODO/FIXME * (D3D12) Backport https://github.com/libretro/RetroArch/pull/12916/commits/c1b6c0bff2aa33cde035b43cb31ac7e78ff2a07a - Fixed resource transition for present when HDR is off Fixed cel shader displaying all black as blending was enabled when the hdr shader was being applied - turned off blending during this shader * Move d3d12_hdr_uniform_t to dxgi_common.h and rename it dxgi_hdr_uniform_t * (D3D11) Add HDR support * Add TODO/FIXME notes * Cache hdr_enable in video_frame_info_t * Update comment
2021-09-03 06:15:25 +02:00
#ifdef HAVE_DXGI_HDR
struct
{
dxgi_hdr_uniform_t ubo_values;
D3D11Buffer ubo;
float max_output_nits;
float min_output_nits;
float max_cll;
float max_fall;
bool support;
bool enable;
} hdr;
#endif
struct
{
d3d11_shader_t shader;
d3d11_shader_t shader_font;
D3D11Buffer vbo;
int offset;
int capacity;
bool enabled;
} sprites;
2018-02-12 01:19:43 +01:00
#ifdef HAVE_OVERLAY
struct
{
D3D11Buffer vbo;
d3d11_texture_t* textures;
bool enabled;
bool fullscreen;
int count;
} overlays;
#endif
struct
{
2018-01-25 04:57:49 +01:00
d3d11_texture_t texture;
D3D11Buffer vbo;
bool enabled;
bool fullscreen;
} menu;
struct
{
2020-11-15 13:01:55 +01:00
d3d11_texture_t texture[GFX_MAX_FRAME_HISTORY + 1];
D3D11Buffer vbo;
D3D11Buffer ubo;
D3D11_VIEWPORT viewport;
float4_t output_size;
int rotation;
} frame;
2018-01-24 20:51:19 +01:00
struct
{
d3d11_shader_t shader;
D3D11Buffer buffers[SLANG_CBUFFER_MAX];
d3d11_texture_t rt;
d3d11_texture_t feedback;
D3D11_VIEWPORT viewport;
pass_semantics_t semantics;
uint32_t frame_count;
int32_t frame_direction;
} pass[GFX_MAX_SHADERS];
struct video_shader* shader_preset;
struct string_list *gpu_list;
IDXGIAdapter1 *current_adapter;
IDXGIAdapter1 *adapters[D3D11_MAX_GPU_COUNT];
d3d11_texture_t luts[GFX_MAX_TEXTURES];
} d3d11_video_t;
static INLINE void d3d11_release_texture(d3d11_texture_t* texture)
{
Release(texture->handle);
Release(texture->staging);
Release(texture->view);
Release(texture->rt_view);
}
void d3d11_init_texture(D3D11Device device, d3d11_texture_t* texture);
void d3d11_update_texture(
D3D11DeviceContext ctx,
2018-02-04 20:03:27 +01:00
unsigned width,
unsigned height,
unsigned pitch,
DXGI_FORMAT format,
const void* data,
d3d11_texture_t* texture);
DXGI_FORMAT d3d11_get_closest_match(
D3D11Device device, DXGI_FORMAT desired_format, UINT desired_format_support);
bool d3d11_init_shader(
D3D11Device device,
const char* src,
size_t size,
const void* src_name,
LPCSTR vs_entry,
LPCSTR ps_entry,
LPCSTR gs_entry,
const D3D11_INPUT_ELEMENT_DESC* input_element_descs,
UINT num_elements,
d3d11_shader_t* out,
enum d3d11_feature_level_hint hint);