Skip to content

Commit cf4445f

Browse files
committed
Improve sample app support
1 parent d7311e3 commit cf4445f

4 files changed

Lines changed: 74 additions & 17 deletions

File tree

amf/public/include/core/VulkanAMF.h

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@
4141
namespace amf
4242
{
4343
#endif
44+
typedef enum AMF_VULKAN_EXTENSION_TYPE
45+
{
46+
AMF_VULKAN_EXTENSION_UNKNOWN = 0,
47+
AMF_VARIANT_TIMELINE_SEMAPHORE = 1,
48+
} AMF_VULKAN_EXTENSION_TYPE;
49+
4450
typedef struct AMFVulkanDevice
4551
{
4652
amf_size cbSizeof; // sizeof(AMFVulkanDevice)
@@ -55,11 +61,19 @@ namespace amf
5561
amf_size cbSizeof; // sizeof(AMFVulkanSync)
5662
void* pNext; // reserved for extensions
5763
VkSemaphore hSemaphore; // VkSemaphore; can be nullptr
58-
amf_bool bSubmitted; // if true - wait for hSemaphore. re-submit hSemaphore if not synced by other ways and set to true
64+
amf_bool bSubmitted; // if true - wait for hSemaphore. re-submit hSemaphore if not synced by other ways and set to true, ignored if timeline
5965
VkFence hFence; // To sync on CPU; can be nullptr. Submitted in vkQueueSubmit. If waited for hFence, null it, do not delete or reset.
6066
} AMFVulkanSync;
6167

62-
typedef struct AMFVulkanBuffer
68+
typedef struct AMFVulkanTimeline // can be attached to AMFVulkanSync::pNext
69+
{
70+
amf_size cbSizeof; // sizeof(AMFVulkanTimeline)
71+
AMF_VULKAN_EXTENSION_TYPE eExtensionType;// identifies extensions to make extension chains in the future AMF_VARIANT_TIMELINE_SEMAPHORE
72+
void* pNext; // reserved for extensions
73+
amf_uint64 uiCount; // count for timeline semaphores
74+
} AMFVulkanTimeline;
75+
76+
typedef struct AMFVulkanBuffer
6377
{
6478
amf_size cbSizeof; // sizeof(AMFVulkanBuffer)
6579
void* pNext; // reserved for extensions
@@ -112,6 +126,7 @@ namespace amf
112126
} AMFVulkanView;
113127

114128
#define AMF_CONTEXT_VULKAN_COMPUTE_QUEUE L"VulkanComputeQueue" // amf_int64; default=0; Compute queue index in range [0, (VkQueueFamilyProperties.queueCount-1)] of the compute queue family.
129+
#define AMF_CONTEXT_VULKAN_USE_TIMELINE_SEMAPHORES L"VulkanTimelineSemaphores" // amf_bool; default=false; Use timeline semaphores in Vulkan
115130

116131
#if defined(__cplusplus)
117132
} // namespace amf

amf/public/samples/CPPSamples/common/PlaybackPipelineBase.cpp

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ PlaybackPipelineBase::PlaybackPipelineBase() :
100100
SetParamDescription(PARAM_NAME_SIDE_BY_SIDE, ParamCommon, L"Specifies Side-by-Side mode, true, false, default false", ParamConverterBoolean);
101101
SetParamDescription(PARAM_NAME_HQ_SCALER_RGB, ParamCommon, L"Force RGB scaling, true, false, default false", ParamConverterBoolean);
102102
SetParamDescription(PARAM_NAME_HQ_SCALER_RATIO, ParamCommon, L"Scaling Ratio (1.3x, 1.5x, 1.7x, 2.0x), default 2.0x", ParamConverterRatio);
103-
SetParamDescription(PARAM_NAME_ENABLE_AUDIO, ParamCommon, L"Enables audio playback, boolean, default = true", ParamConverterDouble);
103+
SetParamDescription(PARAM_NAME_ENABLE_AUDIO, ParamCommon, L"Enables audio playback, boolean, default = true", ParamConverterBoolean);
104104
SetParamDescription(PARAM_NAME_HQSCALER_SHARPNESS, ParamCommon, L"Specifies FSR RCAS attenuation, double, default = 0.75", ParamConverterDouble);
105105
SetParamDescription(PARAM_NAME_FRAME_RATE, ParamCommon, L"Frame Rate (off, 15fps, 30fps, 60fps), default = off", ParamConverterInt64);
106106
SetParamDescription(PARAM_NAME_FRC_ENGINE, ParamCommon, L"Frame Rate Conversion, (DX11, DX12) default = from '-presenter'", ParamConverterFRCEngine);
@@ -122,7 +122,7 @@ PlaybackPipelineBase::PlaybackPipelineBase() :
122122
SetParam(PARAM_NAME_SIDE_BY_SIDE, false);
123123
SetParam(PARAM_NAME_HQ_SCALER_RGB, false);
124124
SetParam(PARAM_NAME_HQ_SCALER_RATIO, AMFRatio({ 20, 10 }));
125-
SetParam(PARAM_NAME_ENABLE_AUDIO, false);
125+
SetParam(PARAM_NAME_ENABLE_AUDIO, true);
126126
SetParam(PARAM_NAME_HQSCALER_SHARPNESS, 0.75);
127127
SetParam(PARAM_NAME_FRAME_RATE, 0);
128128
#if defined(_WIN32)
@@ -146,11 +146,6 @@ PlaybackPipelineBase::~PlaybackPipelineBase()
146146
void PlaybackPipelineBase::Terminate()
147147
{
148148
Stop();
149-
if (m_pContext != nullptr)
150-
{
151-
m_pContext->Terminate();
152-
m_pContext = NULL;
153-
}
154149
}
155150

156151
AMF_RESULT PlaybackPipelineBase::GetDuration(amf_pts& duration) const
@@ -445,6 +440,23 @@ AMF_RESULT PlaybackPipelineBase::Init()
445440
{
446441
LOG_AMF_ERROR(res, L"InitAudio() failed");
447442
iAudioStreamIndex = -1;
443+
if (m_pAudioDecoder != NULL)
444+
{
445+
m_pAudioDecoder->Terminate();
446+
m_pAudioDecoder = NULL;
447+
}
448+
449+
if (m_pAudioConverter != NULL)
450+
{
451+
m_pAudioConverter->Terminate();
452+
m_pAudioConverter = NULL;
453+
}
454+
455+
if (m_pAudioPresenter != NULL)
456+
{
457+
m_pAudioPresenter = NULL;
458+
}
459+
448460
}
449461
// CHECK_AMF_ERROR_RETURN(res, L"InitAudio() failed");
450462
}
@@ -559,7 +571,7 @@ AMF_RESULT PlaybackPipelineBase::ConnectScaler()
559571
}
560572
return res;
561573
}
562-
AMF_RESULT PlaybackPipelineBase::InitVideoPipeline(amf_uint32 /* iVideoStreamIndex */, PipelineElementPtr pVideoSourceStream)
574+
AMF_RESULT PlaybackPipelineBase::InitVideoPipeline(amf_uint32 /* iVideoStreamIndex */, PipelineElementPtr /*pVideoSourceStream*/)
563575
{
564576
bool bAllocator = true;
565577

@@ -677,7 +689,6 @@ AMF_RESULT PlaybackPipelineBase::InitFRC(amf::AMF_MEMORY_TYPE type)
677689
bForceFRCRGB = false;
678690
}
679691

680-
681692
res = g_AMFFactory.GetFactory()->CreateComponent(m_pContext, AMFFRC, &m_pFRC);
682693
CHECK_AMF_ERROR_RETURN(res, L"g_AMFFactory.GetFactory()->CreateComponent(" << AMFFRC << L") failed");
683694
//m_pFRC->SetProperty(AMF_HQ_SCALER_ENGINE_TYPE, type);
@@ -689,7 +700,6 @@ AMF_RESULT PlaybackPipelineBase::InitFRC(amf::AMF_MEMORY_TYPE type)
689700

690701
m_pFRC->SetProperty(AMF_FRC_ENGINE_TYPE, frcEngineType);
691702

692-
693703
m_pFRC->SetProperty(AMF_FRC_MODE, frcMode);
694704

695705
amf_int64 frcFlag = 0;
@@ -1158,14 +1168,11 @@ AMF_RESULT PlaybackPipelineBase::Stop()
11581168
m_pDemuxerAudio->Terminate();
11591169
m_pDemuxerAudio = NULL;
11601170
}
1161-
1162-
11631171
if(m_pContext != NULL)
11641172
{
11651173
m_pContext->Terminate();
11661174
m_pContext = NULL;
11671175
}
1168-
11691176
return AMF_OK;
11701177
}
11711178

amf/public/samples/CPPSamples/common/SwapChainVulkan.cpp

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -758,7 +758,7 @@ VkFormat SwapChainVulkan::GetSupportedVkFormat(AMF_SURFACE_FORMAT format)
758758
case AMF_SURFACE_BGRA: return VK_FORMAT_B8G8R8A8_UNORM;
759759
case AMF_SURFACE_RGBA: return VK_FORMAT_R8G8B8A8_UNORM;
760760
case AMF_SURFACE_RGBA_F16: return VK_FORMAT_R16G16B16A16_SFLOAT;
761-
case AMF_SURFACE_R10G10B10A2: return VK_FORMAT_A2R10G10B10_UNORM_PACK32;
761+
case AMF_SURFACE_R10G10B10A2: return VK_FORMAT_A2B10G10R10_UNORM_PACK32;
762762
}
763763

764764
return VK_FORMAT_UNDEFINED;
@@ -1403,6 +1403,14 @@ AMF_RESULT CommandBufferVulkan::Execute(VkQueue hQueue)
14031403
submitInfo.signalSemaphoreCount = (amf_uint32)m_signalSemaphores.size();
14041404
submitInfo.pSignalSemaphores = &m_signalSemaphores[0];
14051405
}
1406+
1407+
VkTimelineSemaphoreSubmitInfo timelineSemaphoreSubmitInfo = {VK_STRUCTURE_TYPE_TIMELINE_SEMAPHORE_SUBMIT_INFO};
1408+
timelineSemaphoreSubmitInfo.waitSemaphoreValueCount = (uint32_t)m_waitSemaphoresValues.size();
1409+
timelineSemaphoreSubmitInfo.pWaitSemaphoreValues = m_waitSemaphoresValues.data();
1410+
timelineSemaphoreSubmitInfo.signalSemaphoreValueCount = (uint32_t)m_signalSemaphoresValues.size();
1411+
timelineSemaphoreSubmitInfo.pSignalSemaphoreValues= m_signalSemaphoresValues.data();
1412+
submitInfo.pNext = &timelineSemaphoreSubmitInfo;
1413+
14061414
submitInfo.commandBufferCount = 1;
14071415
submitInfo.pCommandBuffers = &m_hCmdBuffer;
14081416

@@ -1421,6 +1429,9 @@ AMF_RESULT CommandBufferVulkan::Execute(VkQueue hQueue)
14211429
m_waitFlags.clear();
14221430
m_signalSemaphores.clear();
14231431
m_pSyncFences.clear();
1432+
m_waitSemaphoresValues.clear();
1433+
m_signalSemaphoresValues.clear();
1434+
14241435

14251436
return AMF_OK;
14261437
}
@@ -1432,17 +1443,39 @@ AMF_RESULT CommandBufferVulkan::SyncResource(amf::AMFVulkanSync* pSync, VkPipeli
14321443

14331444
if (pSync->hSemaphore != VK_NULL_HANDLE)
14341445
{
1446+
AMFVulkanTimeline* sync1 = (AMFVulkanTimeline*)pSync->pNext;
1447+
while (sync1 != nullptr)
1448+
{
1449+
if (sync1->eExtensionType == AMF_VARIANT_TIMELINE_SEMAPHORE)
1450+
{
1451+
break;
1452+
}
1453+
sync1 = (AMFVulkanTimeline*)sync1->pNext;
1454+
}
1455+
uint64_t value = 0;
1456+
if (sync1 != nullptr)
1457+
{
1458+
value = sync1->uiCount;
1459+
}
14351460
amf_vector<VkSemaphore>::iterator it = std::find(m_signalSemaphores.begin(), m_signalSemaphores.end(), pSync->hSemaphore);
14361461
if (it == m_signalSemaphores.end())
14371462
{
1438-
if (pSync->bSubmitted)
1463+
1464+
if (pSync->bSubmitted || sync1 != nullptr)
14391465
{
14401466
m_waitSemaphores.push_back(pSync->hSemaphore);
1467+
m_waitSemaphoresValues.push_back(value);
14411468
m_waitFlags.push_back(waitFlags);
14421469
pSync->bSubmitted = false;
14431470
}
14441471

14451472
m_signalSemaphores.push_back(pSync->hSemaphore);
1473+
if (sync1 != nullptr)
1474+
{
1475+
sync1->uiCount++;
1476+
value = sync1->uiCount;
1477+
}
1478+
m_signalSemaphoresValues.push_back(value);
14461479
pSync->bSubmitted = true;
14471480
}
14481481
else

amf/public/samples/CPPSamples/common/SwapChainVulkan.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ class CommandBufferVulkan : public VulkanContext
9999

100100
amf::amf_vector<VkSemaphore> m_waitSemaphores;
101101
amf::amf_vector<VkSemaphore> m_signalSemaphores;
102+
amf::amf_vector<uint64_t> m_waitSemaphoresValues;
103+
amf::amf_vector<uint64_t> m_signalSemaphoresValues;
102104
amf::amf_vector<VkPipelineStageFlags> m_waitFlags;
103105
amf::amf_vector<VkFence*> m_pSyncFences;
104106

0 commit comments

Comments
 (0)