Skip to content

Commit 3a7ec70

Browse files
committed
create GPU encoder for the same D3D11 device
1 parent 02ce905 commit 3a7ec70

File tree

1 file changed

+26
-3
lines changed

1 file changed

+26
-3
lines changed

ScreenBuddy.c

+26-3
Original file line numberDiff line numberDiff line change
@@ -539,16 +539,39 @@ static bool Buddy_CreateEncoder(ScreenBuddy* Buddy, int EncodeWidth, int EncodeH
539539
MFT_REGISTER_TYPE_INFO Input = { .guidMajorType = MFMediaType_Video, .guidSubtype = MFVideoFormat_NV12 };
540540
MFT_REGISTER_TYPE_INFO Output = { .guidMajorType = MFMediaType_Video, .guidSubtype = MFVideoFormat_H264 };
541541

542+
DXGI_ADAPTER_DESC AdapterDesc;
543+
{
544+
IDXGIDevice* DxgiDevice;
545+
HR(ID3D11Device_QueryInterface(Buddy->Device, &IID_IDXGIDevice, (void**)&DxgiDevice));
546+
547+
IDXGIAdapter* DxgiAdapter;
548+
HR(IDXGIDevice_GetAdapter(DxgiDevice, &DxgiAdapter));
549+
550+
IDXGIAdapter_GetDesc(DxgiAdapter, &AdapterDesc);
551+
552+
IDXGIAdapter_Release(DxgiAdapter);
553+
IDXGIDevice_Release(DxgiDevice);
554+
}
555+
556+
IMFAttributes* EnumAttributes;
557+
HR(MFCreateAttributes(&EnumAttributes, 1));
558+
HR(IMFAttributes_SetBlob(EnumAttributes, &MFT_ENUM_ADAPTER_LUID, (UINT8*)&AdapterDesc.AdapterLuid, sizeof(AdapterDesc.AdapterLuid)));
559+
542560
IMFActivate** Activate;
543561
UINT32 ActivateCount;
544-
HR(MFTEnumEx(MFT_CATEGORY_VIDEO_ENCODER, MFT_ENUM_FLAG_ASYNCMFT | MFT_ENUM_FLAG_HARDWARE | MFT_ENUM_FLAG_SORTANDFILTER, &Input, &Output, &Activate, &ActivateCount));
562+
HR(MFTEnum2(MFT_CATEGORY_VIDEO_ENCODER, MFT_ENUM_FLAG_ASYNCMFT | MFT_ENUM_FLAG_HARDWARE | MFT_ENUM_FLAG_SORTANDFILTER, &Input, &Output, EnumAttributes, &Activate, &ActivateCount));
563+
IMFAttributes_Release(EnumAttributes);
545564

546565
if (ActivateCount == 0)
547566
{
548-
MessageBoxW(Buddy->DialogWindow, L"Cannot create GPU decoder!", L"Error", MB_ICONERROR);
567+
MessageBoxW(Buddy->DialogWindow, L"Cannot create GPU encoder!", L"Error", MB_ICONERROR);
549568
return false;
550569
}
551570

571+
//wchar_t Name[256];
572+
//HR(IMFActivate_GetString(Activate[0], &MFT_FRIENDLY_NAME_Attribute, Name, ARRAYSIZE(Name), NULL));
573+
//OutputDebugStringW(Name);
574+
552575
IMFTransform* Encoder;
553576
HR(IMFActivate_ActivateObject(Activate[0], &IID_IMFTransform, (void**)&Encoder));
554577
for (UINT32 Index = 0; Index < ActivateCount; Index++)
@@ -759,7 +782,7 @@ static bool Buddy_CreateDecoder(ScreenBuddy* Buddy)
759782

760783
if (ActivateCount == 0)
761784
{
762-
MessageBoxW(Buddy->DialogWindow, L"Cannot create GPU encoder!", L"Error", MB_ICONERROR);
785+
MessageBoxW(Buddy->DialogWindow, L"Cannot create GPU decoder!", L"Error", MB_ICONERROR);
763786
return false;
764787
}
765788

0 commit comments

Comments
 (0)