d3d11_fmt.h 5.3 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
/*****************************************************************************
 * d3d11_fmt.h : D3D11 helper calls
 *****************************************************************************
 * Copyright © 2017 VLC authors, VideoLAN and VideoLabs
 *
 * Authors: Steve Lhomme <robux4@gmail.com>
 *
 * This program 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.
 *
 * This program 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 this program; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
 *****************************************************************************/

#ifndef VLC_VIDEOCHROMA_D3D11_FMT_H_
#define VLC_VIDEOCHROMA_D3D11_FMT_H_

#include <d3d11.h>

#include "dxgi_fmt.h"

30 31
DEFINE_GUID(GUID_CONTEXT_MUTEX, 0x472e8835, 0x3f8e, 0x4f93, 0xa0, 0xcb, 0x25, 0x79, 0x77, 0x6c, 0xed, 0x86);

32 33 34 35 36 37
/* see https://msdn.microsoft.com/windows/hardware/commercialize/design/compatibility/device-graphics */
struct wddm_version
{
    int wddm, d3d_features, revision, build;
};

38 39 40 41
typedef struct
{
    ID3D11Device             *d3ddevice;       /* D3D device */
    ID3D11DeviceContext      *d3dcontext;      /* D3D context */
42
    bool                     owner;
43 44 45
#if !VLC_WINSTORE_APP
    struct wddm_version      WDDM;
#endif
46
} d3d11_device_t;
47

48 49 50 51
typedef struct
{
#if !VLC_WINSTORE_APP
    HINSTANCE                 hdll;       /* handle of the opened d3d11 dll */
52 53 54
#if !defined(NDEBUG) && defined(HAVE_DXGIDEBUG_H)
    HINSTANCE                 dxgidebug_dll;
#endif
55 56 57
#endif
} d3d11_handle_t;

58
/* owned by the vout for VLC_CODEC_D3D11_OPAQUE */
59 60 61
struct picture_sys_t
{
    ID3D11VideoDecoderOutputView  *decoder; /* may be NULL for pictures from the pool */
62
    union {
63 64
        ID3D11Texture2D           *texture[D3D11_MAX_SHADER_VIEW];
        ID3D11Resource            *resource[D3D11_MAX_SHADER_VIEW];
65
    };
66 67
    ID3D11DeviceContext           *context;
    unsigned                      slice_index;
68 69
    ID3D11VideoProcessorInputView  *processorInput;  /* when used as processor input */
    ID3D11VideoProcessorOutputView *processorOutput; /* when used as processor output */
70
    ID3D11ShaderResourceView      *resourceView[D3D11_MAX_SHADER_VIEW];
71
    DXGI_FORMAT                   formatTexture;
72 73
};

74
#include "../codec/avcodec/va_surface.h"
75

76
picture_sys_t *ActivePictureSys(picture_t *p_pic);
77

78 79 80 81
/* index to use for texture/resource that use a known DXGI format
 * (ie not DXGI_FORMAT_UNKNWON) */
#define KNOWN_DXGI_INDEX   0

82 83 84 85 86 87
static inline bool is_d3d11_opaque(vlc_fourcc_t chroma)
{
    return chroma == VLC_CODEC_D3D11_OPAQUE ||
           chroma == VLC_CODEC_D3D11_OPAQUE_10B;
}

88
void AcquirePictureSys(picture_sys_t *p_sys);
89

90
void ReleasePictureSys(picture_sys_t *p_sys);
91

92
/* map texture planes to resource views */
93
int AllocateShaderView(vlc_object_t *obj, ID3D11Device *d3ddevice,
94
                              const d3d_format_t *format,
95
                              ID3D11Texture2D *p_texture[D3D11_MAX_SHADER_VIEW], UINT slice_index,
96
                              ID3D11ShaderResourceView *resourceView[D3D11_MAX_SHADER_VIEW]);
97

98
HRESULT D3D11_CreateDevice(vlc_object_t *obj, d3d11_handle_t *,
99
                           bool hw_decoding, d3d11_device_t *out);
100
#define D3D11_CreateDevice(a,b,c,d)  D3D11_CreateDevice( VLC_OBJECT(a), b, c, d )
101

102 103
void D3D11_ReleaseDevice(d3d11_device_t *);

104 105 106 107 108
int D3D11_Create(vlc_object_t *, d3d11_handle_t *);
#define D3D11_Create(a,b) D3D11_Create( VLC_OBJECT(a), b )

void D3D11_Destroy(d3d11_handle_t *);

109 110 111
bool isXboxHardware(ID3D11Device *d3ddev);
bool isNvidiaHardware(ID3D11Device *d3ddev);
IDXGIAdapter *D3D11DeviceAdapter(ID3D11Device *d3ddev);
112
int D3D11CheckDriverVersion(d3d11_device_t *, UINT vendorId,
113
                            const struct wddm_version *min_ver);
114

115 116 117 118 119 120 121
static inline bool DeviceSupportsFormat(ID3D11Device *d3ddevice,
                                        DXGI_FORMAT format, UINT supportFlags)
{
    UINT i_formatSupport;
    return SUCCEEDED( ID3D11Device_CheckFormatSupport(d3ddevice, format,
                                                      &i_formatSupport) )
            && ( i_formatSupport & supportFlags ) == supportFlags;
122 123
}

124
const d3d_format_t *FindD3D11Format(ID3D11Device *d3ddevice,
125 126 127 128 129
                                    vlc_fourcc_t i_src_chroma,
                                    bool rgb_only,
                                    uint8_t bits_per_channel,
                                    bool allow_opaque,
                                    UINT supportFlags);
130

131
int AllocateTextures(vlc_object_t *obj, d3d11_device_t *d3d_dev,
132 133 134
                     const d3d_format_t *cfg, const video_format_t *fmt,
                     unsigned pool_size, ID3D11Texture2D *textures[]);

135 136 137 138 139
#ifndef NDEBUG
void D3D11_LogProcessorSupport(vlc_object_t*, ID3D11VideoProcessorEnumerator*);
#define D3D11_LogProcessorSupport(a,b) D3D11_LogProcessorSupport( VLC_OBJECT(a), b )
#endif

140
#endif /* include-guard */