[PATCH] mfplat/allocator: Handle bind flags and usage attributes.

Nikolay Sivov nsivov at codeweavers.com
Fri Feb 12 11:40:20 CST 2021


Signed-off-by: Nikolay Sivov <nsivov at codeweavers.com>
---
 dlls/mfplat/sample.c | 33 ++++++++++++++++++++++++++++-----
 1 file changed, 28 insertions(+), 5 deletions(-)

diff --git a/dlls/mfplat/sample.c b/dlls/mfplat/sample.c
index 4ecce4fbe84..0581c6c2484 100644
--- a/dlls/mfplat/sample.c
+++ b/dlls/mfplat/sample.c
@@ -72,6 +72,8 @@ struct sample_allocator
         unsigned int height;
         D3DFORMAT d3d9_format;
         DXGI_FORMAT dxgi_format;
+        unsigned int usage;
+        unsigned int bindflags;
         unsigned int buffer_count;
     } frame_desc;
 
@@ -1345,8 +1347,12 @@ static HRESULT sample_allocator_allocate_sample(struct sample_allocator *allocat
             desc.Format = allocator->frame_desc.dxgi_format;
             desc.SampleDesc.Count = 1;
             desc.SampleDesc.Quality = 0;
-            desc.Usage = 0;
-            desc.BindFlags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_RENDER_TARGET;
+            desc.Usage = allocator->frame_desc.usage;
+            desc.BindFlags = allocator->frame_desc.bindflags;
+            if (desc.Usage == D3D11_USAGE_DYNAMIC)
+                desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
+            else if (desc.Usage == D3D11_USAGE_STAGING)
+                desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE | D3D11_CPU_ACCESS_READ;
 
             if (SUCCEEDED(hr = ID3D11Device_CreateTexture2D(service->d3d11_device, &desc, NULL, &texture)))
             {
@@ -1395,15 +1401,32 @@ static HRESULT sample_allocator_initialize(struct sample_allocator *allocator, u
     if (sample_count > max_sample_count)
         return E_INVALIDARG;
 
+    allocator->frame_desc.usage = D3D11_USAGE_DEFAULT;
+    if (attributes)
+    {
+        IMFAttributes_GetUINT32(attributes, &MF_SA_BUFFERS_PER_SAMPLE, &allocator->frame_desc.buffer_count);
+        IMFAttributes_GetUINT32(attributes, &MF_SA_D3D11_USAGE, &allocator->frame_desc.usage);
+    }
+
+    if (allocator->frame_desc.usage == D3D11_USAGE_IMMUTABLE || allocator->frame_desc.usage > D3D11_USAGE_STAGING)
+        return E_INVALIDARG;
+
+    if (allocator->frame_desc.usage == D3D11_USAGE_DEFAULT)
+        allocator->frame_desc.bindflags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_RENDER_TARGET;
+    else if (allocator->frame_desc.usage == D3D11_USAGE_DYNAMIC)
+        allocator->frame_desc.bindflags = D3D11_BIND_SHADER_RESOURCE;
+    else
+        allocator->frame_desc.bindflags = 0;
+
+    if (attributes)
+        IMFAttributes_GetUINT32(attributes, &MF_SA_D3D11_BINDFLAGS, &allocator->frame_desc.bindflags);
+
     sample_allocator_set_media_type(allocator, media_type);
     sample_allocator_set_attributes(allocator, attributes);
 
     sample_count = max(1, sample_count);
     max_sample_count = max(1, max_sample_count);
 
-    if (attributes)
-        IMFAttributes_GetUINT32(attributes, &MF_SA_BUFFERS_PER_SAMPLE, &allocator->frame_desc.buffer_count);
-
     allocator->frame_desc.d3d9_format = subtype.Data1;
     allocator->frame_desc.dxgi_format = MFMapDX9FormatToDXGIFormat(allocator->frame_desc.d3d9_format);
     allocator->frame_desc.width = frame_size >> 32;
-- 
2.30.0




More information about the wine-devel mailing list