Conor McCarthy : vkd3d: Return E_INVALIDARG if a heap is too small for a placed resource.

Alexandre Julliard julliard at winehq.org
Mon Jul 26 15:28:33 CDT 2021


Module: vkd3d
Branch: master
Commit: e292351fa98915e66349bafe5f89239cf442d6e6
URL:    https://source.winehq.org/git/vkd3d.git/?a=commit;h=e292351fa98915e66349bafe5f89239cf442d6e6

Author: Conor McCarthy <cmccarthy at codeweavers.com>
Date:   Mon Jul 26 13:47:39 2021 +1000

vkd3d: Return E_INVALIDARG if a heap is too small for a placed resource.

Otherwise vkBindBufferMemory() or vkBindImageMemory() will fail, which
can result in a generic E_FAIL.

Based on a vkd3d-proton patch by Samuel Pitoiset which fixes a GPU hang
with Cyberpunk 2077.

Signed-off-by: Conor McCarthy <cmccarthy at codeweavers.com>
Signed-off-by: Henri Verbeet <hverbeet at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 libs/vkd3d/resource.c | 7 +++++++
 tests/d3d12.c         | 1 -
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/libs/vkd3d/resource.c b/libs/vkd3d/resource.c
index 3faa679..1ca23a9 100644
--- a/libs/vkd3d/resource.c
+++ b/libs/vkd3d/resource.c
@@ -1911,6 +1911,13 @@ static HRESULT vkd3d_bind_heap_memory(struct d3d12_device *device,
         heap_offset = align(heap_offset, requirements.alignment);
     }
 
+    if (heap_offset > heap->desc.SizeInBytes || requirements.size > heap->desc.SizeInBytes - heap_offset)
+    {
+        ERR("Heap too small for the resource (offset %"PRIu64", resource size %"PRIu64", heap size %"PRIu64".\n",
+                heap_offset, requirements.size, heap->desc.SizeInBytes);
+        return E_INVALIDARG;
+    }
+
     if (heap_offset % requirements.alignment)
     {
         FIXME("Invalid heap offset %#"PRIx64" (alignment %#"PRIx64").\n",
diff --git a/tests/d3d12.c b/tests/d3d12.c
index e4fed2c..fbf14a2 100644
--- a/tests/d3d12.c
+++ b/tests/d3d12.c
@@ -2290,7 +2290,6 @@ static void test_create_placed_resource(void)
     hr = ID3D12Device_CreatePlacedResource(device, heap, heap_desc.SizeInBytes,
             &resource_desc, D3D12_RESOURCE_STATE_COMMON, NULL,
             &IID_ID3D12Resource, (void **)&resource);
-    todo
     ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
 
     ID3D12Heap_Release(heap);




More information about the wine-cvs mailing list