[PATCH 3/6] vkd3d: Deal with Map out parameter being NULL.

Hans-Kristian Arntzen post at arntzen-software.no
Mon Sep 30 09:16:38 CDT 2019


It is possible to map a resource, but not disclose the VA to caller.
This is used for WriteToSubresource.

Signed-off-by: Hans-Kristian Arntzen <post at arntzen-software.no>
---
 libs/vkd3d/resource.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/libs/vkd3d/resource.c b/libs/vkd3d/resource.c
index 87277f7..4ba7586 100644
--- a/libs/vkd3d/resource.c
+++ b/libs/vkd3d/resource.c
@@ -431,7 +431,9 @@ static HRESULT d3d12_heap_map(struct d3d12_heap *heap, uint64_t offset,
     {
         TRACE("Mapping persistently mapped heap %p.\n", heap);
         assert(heap->map_ptr);
-        *data = (BYTE *)heap->map_ptr + offset;
+        /* Data may be null, in which case we still need to map, but don't have to disclose CPU VA. */
+        if (data)
+            *data = (BYTE *)heap->map_ptr + offset;
         return S_OK;
     }
 
@@ -471,13 +473,15 @@ static HRESULT d3d12_heap_map(struct d3d12_heap *heap, uint64_t offset,
     if (hr == S_OK)
     {
         assert(heap->map_ptr);
-        *data = (BYTE *)heap->map_ptr + offset;
+        if (data)
+            *data = (BYTE *)heap->map_ptr + offset;
         ++resource->map_count;
     }
     else
     {
         assert(!heap->map_ptr);
-        *data = NULL;
+        if (data)
+            *data = NULL;
     }
 
     pthread_mutex_unlock(&heap->mutex);
@@ -1268,7 +1272,8 @@ static HRESULT STDMETHODCALLTYPE d3d12_resource_Map(ID3D12Resource *iface, UINT
     if (FAILED(hr = d3d12_heap_map(resource->heap, resource->heap_offset, resource, data)))
         WARN("Failed to map resource %p, hr %#x.\n", resource, hr);
 
-    TRACE("Returning pointer %p.\n", *data);
+    if (data)
+        TRACE("Returning pointer %p.\n", *data);
 
     return hr;
 }
-- 
2.23.0




More information about the wine-devel mailing list