Replace deprecated DXVA2 initialization with standard hwaccel init

- Avoids requiring a hardcoded number of frames (and creating surfaces ourselves)
- Removes a ton of unnecessary code that's duplicated in FFmpeg
- Supports dynamic frame sizes, formats, and color conversion
- Supports frame cropping in FFmpeg
This commit is contained in:
Cameron Gutman
2026-01-11 17:46:13 -06:00
parent c14ebb1ad7
commit b8e9262b1b
2 changed files with 208 additions and 404 deletions
+3 -32
View File
@@ -6,10 +6,6 @@
#include <d3d9.h>
#include <dxva2api.h>
extern "C" {
#include <libavcodec/dxva2.h>
}
#include <wrl/client.h>
class DXVA2Renderer : public IFFmpegRenderer
@@ -27,52 +23,27 @@ public:
private:
bool initializeDecoder();
bool initializeRenderer();
bool initializeVideoProcessor();
bool initializeDevice(SDL_Window* window, bool enableVsync);
bool isDecoderBlacklisted();
bool initializeQuirksForAdapter(IDirect3D9Ex* d3d9ex, int adapterIndex);
void renderOverlay(Overlay::OverlayType type);
#if LIBAVUTIL_VERSION_INT >= AV_VERSION_INT(56, 68, 0)
#define FF_POOL_SIZE_TYPE size_t
#else
#define FF_POOL_SIZE_TYPE int
#endif
static
AVBufferRef* ffPoolAlloc(void* opaque, FF_POOL_SIZE_TYPE size);
static
void ffPoolDummyDelete(void*, uint8_t*);
static
int ffGetBuffer2(AVCodecContext* context, AVFrame* frame, int flags);
int m_DecoderSelectionPass;
int m_VideoFormat;
int m_VideoWidth;
int m_VideoHeight;
int m_DisplayWidth;
int m_DisplayHeight;
struct dxva_context m_DXVAContext;
// H.264 uses a maximum of 16 reference frames
std::array<Microsoft::WRL::ComPtr<IDirect3DSurface9>, 16 + PACER_MAX_OUTSTANDING_FRAMES> m_DecSurfaces;
std::array<IDirect3DSurface9*, 16 + PACER_MAX_OUTSTANDING_FRAMES> m_DecSurfacesRaw; // Referenced by m_DecSurfaces
DXVA2_ConfigPictureDecode m_Config;
Microsoft::WRL::ComPtr<IDirectXVideoDecoderService> m_DecService;
Microsoft::WRL::ComPtr<IDirectXVideoDecoder> m_Decoder;
int m_SurfacesUsed;
AVBufferPool* m_Pool;
AVBufferRef* m_HwDeviceContext;
SDL_SpinLock m_OverlayLock;
std::array<Microsoft::WRL::ComPtr<IDirect3DVertexBuffer9>, Overlay::OverlayMax> m_OverlayVertexBuffers;
std::array<Microsoft::WRL::ComPtr<IDirect3DTexture9>, Overlay::OverlayMax> m_OverlayTextures;
Microsoft::WRL::ComPtr<IDirect3DDevice9Ex> m_Device;
Microsoft::WRL::ComPtr<IDirect3DDeviceManager9> m_DeviceManager;
Microsoft::WRL::ComPtr<IDirect3DSurface9> m_RenderTarget;
Microsoft::WRL::ComPtr<IDirectXVideoProcessorService> m_ProcService;
Microsoft::WRL::ComPtr<IDirectXVideoProcessor> m_Processor;