2017-08-15 13:39:55 +00:00
|
|
|
/*
|
|
|
|
* This file is part of mpv.
|
|
|
|
*
|
|
|
|
* mpv is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* mpv is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with mpv. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef MP_D3D11_HELPERS_H_
|
|
|
|
#define MP_D3D11_HELPERS_H_
|
|
|
|
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <windows.h>
|
|
|
|
#include <d3d11.h>
|
|
|
|
#include <dxgi1_2.h>
|
2024-03-06 05:41:53 +00:00
|
|
|
#include <dxgi1_6.h>
|
2023-05-01 15:43:25 +00:00
|
|
|
|
|
|
|
#if HAVE_DXGI_DEBUG
|
2023-05-01 01:11:15 +00:00
|
|
|
#include <dxgidebug.h>
|
2023-05-01 15:43:25 +00:00
|
|
|
#endif
|
2017-08-15 13:39:55 +00:00
|
|
|
|
2017-10-11 07:10:39 +00:00
|
|
|
#include "video/mp_image.h"
|
|
|
|
|
vo_gpu: d3d11: initial implementation
This is a new RA/vo_gpu backend that uses Direct3D 11. The GLSL
generated by vo_gpu is cross-compiled to HLSL with SPIRV-Cross.
What works:
- All of mpv's internal shaders should work, including compute shaders.
- Some external shaders have been tested and work, including RAVU and
adaptive-sharpen.
- Non-dumb mode works, even on very old hardware. Most features work at
feature level 9_3 and all features work at feature level 10_0. Some
features also work at feature level 9_1 and 9_2, but without high-bit-
depth FBOs, it's not very useful. (Hardware this old is probably not
fast enough for advanced features anyway.)
Note: This is more compatible than ANGLE, which requires 9_3 to work
at all (GLES 2.0,) and 10_1 for non-dumb-mode (GLES 3.0.)
- Hardware decoding with D3D11VA, including decoding of 10-bit formats
without truncation to 8-bit.
What doesn't work / can be improved:
- PBO upload and direct rendering does not work yet. Direct rendering
requires persistent-mapped PBOs because the decoder needs to be able
to read data from images that have already been decoded and uploaded.
Unfortunately, it seems like persistent-mapped PBOs are fundamentally
incompatible with D3D11, which requires all resources to use driver-
managed memory and requires memory to be unmapped (and hence pointers
to be invalidated) when a resource is used in a draw or copy
operation.
However it might be possible to use D3D11's limited multithreading
capabilities to emulate some features of PBOs, like asynchronous
texture uploading.
- The blit() and clear() operations don't have equivalents in the D3D11
API that handle all cases, so in most cases, they have to be emulated
with a shader. This is currently done inside ra_d3d11, but ideally it
would be done in generic code, so it can take advantage of mpv's
shader generation utilities.
- SPIRV-Cross is used through a NIH C-compatible wrapper library, since
it does not expose a C interface itself.
The library is available here: https://github.com/rossy/crossc
- The D3D11 context could be made to support more modern DXGI features
in future. For example, it should be possible to add support for
high-bit-depth and HDR output with DXGI 1.5/1.6.
2017-09-07 10:18:06 +00:00
|
|
|
#define D3D_FEATURE_LEVEL_12_0 (0xc000)
|
|
|
|
#define D3D_FEATURE_LEVEL_12_1 (0xc100)
|
|
|
|
|
2019-10-13 19:51:26 +00:00
|
|
|
#define DXGI_COLOR_SPACE_RGB_STUDIO_G24_NONE_P709 ((DXGI_COLOR_SPACE_TYPE)20)
|
|
|
|
#define DXGI_COLOR_SPACE_RGB_STUDIO_G24_NONE_P2020 ((DXGI_COLOR_SPACE_TYPE)21)
|
|
|
|
#define DXGI_COLOR_SPACE_YCBCR_STUDIO_G24_LEFT_P709 ((DXGI_COLOR_SPACE_TYPE)22)
|
|
|
|
#define DXGI_COLOR_SPACE_YCBCR_STUDIO_G24_LEFT_P2020 ((DXGI_COLOR_SPACE_TYPE)23)
|
|
|
|
#define DXGI_COLOR_SPACE_YCBCR_STUDIO_G24_TOPLEFT_P2020 ((DXGI_COLOR_SPACE_TYPE)24)
|
|
|
|
|
2023-05-01 01:11:15 +00:00
|
|
|
#if !HAVE_DXGI_DEBUG_D3D11
|
|
|
|
DEFINE_GUID(DXGI_DEBUG_D3D11, 0x4b99317b, 0xac39, 0x4aa6, 0xbb, 0xb, 0xba, 0xa0, 0x47, 0x84, 0x79, 0x8f);
|
|
|
|
#endif
|
|
|
|
|
2017-08-15 13:39:55 +00:00
|
|
|
struct d3d11_device_opts {
|
vo_gpu: d3d11: initial implementation
This is a new RA/vo_gpu backend that uses Direct3D 11. The GLSL
generated by vo_gpu is cross-compiled to HLSL with SPIRV-Cross.
What works:
- All of mpv's internal shaders should work, including compute shaders.
- Some external shaders have been tested and work, including RAVU and
adaptive-sharpen.
- Non-dumb mode works, even on very old hardware. Most features work at
feature level 9_3 and all features work at feature level 10_0. Some
features also work at feature level 9_1 and 9_2, but without high-bit-
depth FBOs, it's not very useful. (Hardware this old is probably not
fast enough for advanced features anyway.)
Note: This is more compatible than ANGLE, which requires 9_3 to work
at all (GLES 2.0,) and 10_1 for non-dumb-mode (GLES 3.0.)
- Hardware decoding with D3D11VA, including decoding of 10-bit formats
without truncation to 8-bit.
What doesn't work / can be improved:
- PBO upload and direct rendering does not work yet. Direct rendering
requires persistent-mapped PBOs because the decoder needs to be able
to read data from images that have already been decoded and uploaded.
Unfortunately, it seems like persistent-mapped PBOs are fundamentally
incompatible with D3D11, which requires all resources to use driver-
managed memory and requires memory to be unmapped (and hence pointers
to be invalidated) when a resource is used in a draw or copy
operation.
However it might be possible to use D3D11's limited multithreading
capabilities to emulate some features of PBOs, like asynchronous
texture uploading.
- The blit() and clear() operations don't have equivalents in the D3D11
API that handle all cases, so in most cases, they have to be emulated
with a shader. This is currently done inside ra_d3d11, but ideally it
would be done in generic code, so it can take advantage of mpv's
shader generation utilities.
- SPIRV-Cross is used through a NIH C-compatible wrapper library, since
it does not expose a C interface itself.
The library is available here: https://github.com/rossy/crossc
- The D3D11 context could be made to support more modern DXGI features
in future. For example, it should be possible to add support for
high-bit-depth and HDR output with DXGI 1.5/1.6.
2017-09-07 10:18:06 +00:00
|
|
|
// Enable the debug layer (D3D11_CREATE_DEVICE_DEBUG)
|
|
|
|
bool debug;
|
|
|
|
|
2017-08-15 13:39:55 +00:00
|
|
|
// Allow a software (WARP) adapter. Note, sometimes a software adapter will
|
|
|
|
// be used even when allow_warp is false. This is because, on Windows 8 and
|
|
|
|
// up, if there are no hardware adapters, Windows will pretend the WARP
|
|
|
|
// adapter is the primary hardware adapter.
|
|
|
|
bool allow_warp;
|
|
|
|
|
|
|
|
// Always use a WARP adapter. This is mainly for testing purposes.
|
|
|
|
bool force_warp;
|
|
|
|
|
|
|
|
// The maximum number of pending frames allowed to be queued to a swapchain
|
|
|
|
int max_frame_latency;
|
|
|
|
|
|
|
|
// The maximum Direct3D 11 feature level to attempt to create
|
|
|
|
// If unset, defaults to D3D_FEATURE_LEVEL_11_0
|
|
|
|
int max_feature_level;
|
|
|
|
|
|
|
|
// The minimum Direct3D 11 feature level to attempt to create. If this is
|
|
|
|
// not supported, device creation will fail.
|
|
|
|
// If unset, defaults to D3D_FEATURE_LEVEL_9_1
|
|
|
|
int min_feature_level;
|
2019-04-19 22:28:03 +00:00
|
|
|
|
|
|
|
// The adapter name to utilize if a specific adapter is required
|
|
|
|
// If unset, the default adapter will be utilized when creating
|
|
|
|
// a device.
|
|
|
|
char *adapter_name;
|
2017-08-15 13:39:55 +00:00
|
|
|
};
|
|
|
|
|
2023-11-07 23:01:47 +00:00
|
|
|
IDXGIAdapter1 *mp_get_dxgi_adapter(struct mp_log *log,
|
|
|
|
bstr requested_adapter_name,
|
|
|
|
bstr *listing);
|
|
|
|
|
2024-03-06 05:41:53 +00:00
|
|
|
bool mp_get_dxgi_output_desc(IDXGISwapChain *swapchain, DXGI_OUTPUT_DESC1 *desc);
|
|
|
|
|
2024-02-26 03:55:00 +00:00
|
|
|
OPT_STRING_VALIDATE_FUNC(mp_dxgi_validate_adapter);
|
2023-11-07 23:01:47 +00:00
|
|
|
|
2023-11-07 22:35:39 +00:00
|
|
|
bool mp_dxgi_list_or_verify_adapters(struct mp_log *log,
|
|
|
|
bstr adapter_name,
|
|
|
|
bstr *listing);
|
2019-09-29 15:21:59 +00:00
|
|
|
|
2017-08-15 13:39:55 +00:00
|
|
|
bool mp_d3d11_create_present_device(struct mp_log *log,
|
|
|
|
struct d3d11_device_opts *opts,
|
|
|
|
ID3D11Device **dev_out);
|
|
|
|
|
|
|
|
struct d3d11_swapchain_opts {
|
|
|
|
HWND window;
|
|
|
|
int width;
|
|
|
|
int height;
|
2019-10-11 21:35:22 +00:00
|
|
|
DXGI_FORMAT format;
|
2018-05-06 00:01:58 +00:00
|
|
|
DXGI_COLOR_SPACE_TYPE color_space;
|
|
|
|
|
2023-11-04 02:55:38 +00:00
|
|
|
// pl_color_space mapping of the configured swapchain colorspace
|
2018-05-06 00:01:58 +00:00
|
|
|
// shall be written into this memory location if configuration
|
|
|
|
// succeeds. Will be ignored if NULL.
|
2023-11-04 02:55:38 +00:00
|
|
|
struct pl_color_space *configured_csp;
|
2017-08-15 13:39:55 +00:00
|
|
|
|
|
|
|
// Use DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL if possible
|
|
|
|
bool flip;
|
|
|
|
|
|
|
|
// Number of surfaces in the swapchain
|
|
|
|
int length;
|
|
|
|
|
|
|
|
// The BufferUsage value for swapchain surfaces. This should probably
|
|
|
|
// contain DXGI_USAGE_RENDER_TARGET_OUTPUT.
|
|
|
|
DXGI_USAGE usage;
|
|
|
|
};
|
|
|
|
|
|
|
|
bool mp_d3d11_create_swapchain(ID3D11Device *dev, struct mp_log *log,
|
|
|
|
struct d3d11_swapchain_opts *opts,
|
|
|
|
IDXGISwapChain **swapchain_out);
|
|
|
|
|
2023-05-01 15:43:25 +00:00
|
|
|
#if HAVE_DXGI_DEBUG
|
2023-05-01 01:11:15 +00:00
|
|
|
void mp_d3d11_get_debug_interfaces(struct mp_log *log, IDXGIDebug **debug,
|
|
|
|
IDXGIInfoQueue **iqueue);
|
2023-05-01 15:43:25 +00:00
|
|
|
#endif
|
2023-05-01 01:11:15 +00:00
|
|
|
|
2017-08-15 13:39:55 +00:00
|
|
|
#endif
|