Commit 600ed80b authored by Nikolay Sivov's avatar Nikolay Sivov Committed by Alexandre Julliard

mfplat/allocator: Handle D3D11 resource sharing mode configuration attributes.

parent bf633a97
......@@ -74,6 +74,7 @@ struct sample_allocator
DXGI_FORMAT dxgi_format;
unsigned int usage;
unsigned int bindflags;
unsigned int miscflags;
unsigned int buffer_count;
} frame_desc;
......@@ -1352,6 +1353,7 @@ static HRESULT sample_allocator_allocate_sample(struct sample_allocator *allocat
desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
else if (desc.Usage == D3D11_USAGE_STAGING)
desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE | D3D11_CPU_ACCESS_READ;
desc.MiscFlags = allocator->frame_desc.miscflags;
if (SUCCEEDED(hr = ID3D11Device_CreateTexture2D(service->d3d11_device, &desc, NULL, &texture)))
{
......@@ -1380,7 +1382,7 @@ static HRESULT sample_allocator_initialize(struct sample_allocator *allocator, u
{
struct surface_service service;
DXGI_FORMAT dxgi_format;
unsigned int i;
unsigned int i, value;
GUID major, subtype;
UINT64 frame_size;
IMFSample *sample;
......@@ -1415,6 +1417,7 @@ static HRESULT sample_allocator_initialize(struct sample_allocator *allocator, u
dxgi_format = MFMapDX9FormatToDXGIFormat(subtype.Data1);
allocator->frame_desc.bindflags = 0;
allocator->frame_desc.miscflags = 0;
allocator->frame_desc.usage = D3D11_USAGE_DEFAULT;
if (dxgi_format == DXGI_FORMAT_B8G8R8A8_UNORM ||
......@@ -1428,7 +1431,13 @@ static HRESULT sample_allocator_initialize(struct sample_allocator *allocator, u
}
if (attributes)
{
IMFAttributes_GetUINT32(attributes, &MF_SA_D3D11_BINDFLAGS, &allocator->frame_desc.bindflags);
if (SUCCEEDED(IMFAttributes_GetUINT32(attributes, &MF_SA_D3D11_SHARED, &value)) && value)
allocator->frame_desc.miscflags |= D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX;
if (SUCCEEDED(IMFAttributes_GetUINT32(attributes, &MF_SA_D3D11_SHARED_WITHOUT_MUTEX, &value)) && value)
allocator->frame_desc.miscflags |= D3D11_RESOURCE_MISC_SHARED;
}
sample_allocator_set_media_type(allocator, media_type);
sample_allocator_set_attributes(allocator, attributes);
......
......@@ -6798,6 +6798,12 @@ static void test_sample_allocator(void)
D3D11_USAGE_STAGING,
D3D11_USAGE_STAGING + 1,
};
static const unsigned int sharing[] =
{
D3D11_RESOURCE_MISC_SHARED | D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX,
D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX,
D3D11_RESOURCE_MISC_SHARED,
};
if (!pMFCreateVideoSampleAllocatorEx)
{
......@@ -7155,6 +7161,67 @@ todo_wine
IMFVideoSampleAllocatorEx_Release(allocatorex);
}
/* MF_SA_D3D11_SHARED, MF_SA_D3D11_SHARED_WITHOUT_MUTEX */
for (i = 0; i < ARRAY_SIZE(sharing); ++i)
{
hr = pMFCreateVideoSampleAllocatorEx(&IID_IMFVideoSampleAllocatorEx, (void **)&allocatorex);
ok(hr == S_OK, "Unexpected hr %#x.\n", hr);
hr = IMFVideoSampleAllocatorEx_SetDirectXManager(allocatorex, (IUnknown *)manager);
ok(hr == S_OK, "Unexpected hr %#x.\n", hr);
hr = IMFAttributes_DeleteAllItems(attributes);
ok(hr == S_OK, "Unexpected hr %#x.\n", hr);
hr = IMFAttributes_SetUINT32(attributes, &MF_SA_D3D11_USAGE, D3D11_USAGE_DEFAULT);
ok(hr == S_OK, "Failed to set attribute, hr %#x.\n", hr);
if (sharing[i] & D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX)
{
hr = IMFAttributes_SetUINT32(attributes, &MF_SA_D3D11_SHARED, TRUE);
ok(hr == S_OK, "Failed to set attribute, hr %#x.\n", hr);
}
if (sharing[i] & D3D11_RESOURCE_MISC_SHARED)
{
hr = IMFAttributes_SetUINT32(attributes, &MF_SA_D3D11_SHARED_WITHOUT_MUTEX, TRUE);
ok(hr == S_OK, "Failed to set attribute, hr %#x.\n", hr);
}
hr = IMFVideoSampleAllocatorEx_InitializeSampleAllocatorEx(allocatorex, 0, 0, attributes, video_type);
if (sharing[i] == (D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX | D3D11_RESOURCE_MISC_SHARED))
{
todo_wine
ok(hr == E_INVALIDARG, "%u: Unexpected hr %#x.\n", i, hr);
IMFVideoSampleAllocatorEx_Release(allocatorex);
continue;
}
ok(hr == S_OK, "%u: Unexpected hr %#x.\n", i, hr);
hr = IMFVideoSampleAllocatorEx_AllocateSample(allocatorex, &sample);
ok(hr == S_OK, "Unexpected hr %#x.\n", hr);
hr = IMFSample_GetBufferByIndex(sample, 0, &buffer);
ok(hr == S_OK, "Unexpected hr %#x.\n", hr);
hr = IMFMediaBuffer_QueryInterface(buffer, &IID_IMFDXGIBuffer, (void **)&dxgi_buffer);
ok(hr == S_OK, "Failed to get interface, hr %#x.\n", hr);
hr = IMFDXGIBuffer_GetResource(dxgi_buffer, &IID_ID3D11Texture2D, (void **)&texture);
ok(hr == S_OK, "Failed to get resource, hr %#x.\n", hr);
ID3D11Texture2D_GetDesc(texture, &desc);
ok(desc.MiscFlags == sharing[i], "%u: unexpected misc flags %#x.\n", i, desc.MiscFlags);
ID3D11Texture2D_Release(texture);
IMFDXGIBuffer_Release(dxgi_buffer);
IMFMediaBuffer_Release(buffer);
IMFSample_Release(sample);
IMFVideoSampleAllocatorEx_Release(allocatorex);
}
IMFAttributes_Release(attributes);
IMFDXGIDeviceManager_Release(manager);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment