Files
UnrealEngineUWP/Engine/Plugins/Media/HardwareEncoders/Source/EncoderAMF/Private/Amf_EncoderModule.cpp
christopher waters c001265796 Removing uses of FDynamicRHI::GetName() and GetGraphicsRHI() to identify specific RHIs in favor of ERHIInterfaceType.
Switching direct casts of GDynamicRHI to use the new CastDynamicRHI/GetDynamicRHI functions. This prevents incorrectly casting RHIValidation into the wrong types.

#jira none
#rb josh.adams, will.damon, peter.tarasenko
#preflight 6216a3b9c15ec90be95f54f7

[CL 19116145 by christopher waters in ue5-main branch]
2022-02-24 11:58:36 -05:00

78 lines
1.9 KiB
C++

// Copyright Epic Games, Inc. All Rights Reserved.
#include "Modules/ModuleManager.h"
#include "VulkanRHIPrivate.h"
#include "VulkanRHIBridge.h"
#include "DynamicRHI.h"
#include "Amf_Common.h"
#include "Amf_EncoderH264.h"
#include "VideoEncoderFactory.h"
#include "Misc/CoreDelegates.h"
class FAMFEncoderModule : public IModuleInterface
{
public:
void StartupModule()
{
using namespace AVEncoder;
if(FApp::CanEverRender())
{
FAmfCommon& AMF = FAmfCommon::Setup();
if(AMF.GetIsAvailable())
{
#if PLATFORM_WINDOWS
const TCHAR* DynamicRHIModuleName = GetSelectedDynamicRHIModuleName(false);
#elif PLATFORM_LINUX
const TCHAR* DynamicRHIModuleName = TEXT("VulkanRHI");
#endif
if(FString("VulkanRHI") == FString(DynamicRHIModuleName))
{
#if PLATFORM_WINDOWS || PLATFORM_LINUX
UE_LOG(LogEncoderAMF, Error, TEXT("Vulkan AMF is currently unsuported and has been disabled."));
return;
#endif
AMF.InitializeContext(ERHIInterfaceType::Vulkan, "Vulkan", NULL);
amf::AMFContext1Ptr pContext1(AMF.GetContext());
amf_size NumDeviceExtensions = 0;
pContext1->GetVulkanDeviceExtensions(&NumDeviceExtensions, nullptr);
TArray<const ANSICHAR*> ExtentionsToAdd;
ExtentionsToAdd.AddUninitialized(5);
pContext1->GetVulkanDeviceExtensions(&NumDeviceExtensions, ExtentionsToAdd.GetData());
AMF.DestroyContext();
VulkanRHIBridge::AddEnabledDeviceExtensionsAndLayers(ExtentionsToAdd, TArray<const ANSICHAR*>());
}
FCoreDelegates::OnPostEngineInit.AddLambda([]() {FVideoEncoderAmf_H264::Register(FVideoEncoderFactory::Get());});
AMFStarted = true;
}
}
}
void ShutdownModule()
{
using namespace AVEncoder;
if(AMFStarted)
{
FAmfCommon& AMF = FAmfCommon::Setup();
AMF.Shutdown();
AMFStarted = false;
}
}
private:
bool AMFStarted = false;
};
IMPLEMENT_MODULE(FAMFEncoderModule, EncoderAMF);