radv: Don't underflow non-visible VRAM size.
authorBas Nieuwenhuizen <bas@basnieuwenhuizen.nl>
Sun, 30 Jul 2017 21:26:11 +0000 (23:26 +0200)
committerBas Nieuwenhuizen <bas@basnieuwenhuizen.nl>
Mon, 31 Jul 2017 20:50:13 +0000 (22:50 +0200)
In some APU situations the reported visible size can be larger than
VRAM size. This properly clamps the value.

Surprisingly both CTS and spec seem to allow a heap type with size 0,
so this seemed like the easiest option to me.

Signed-off-by: Bas Nieuwenhuizen <basni@google.com>
Fixes: 4ae84efbc5c "radv: Use enum for memory heaps."
Reviewed-by: Dave Airlie <airlied@redhat.com>
Reviewed-by: Michel Dänzer <michel.daenzer@amd.com>
Tested-by: Michel Dänzer <michel.daenzer@amd.com>
src/amd/vulkan/radv_device.c

index eb2587212c8ca69a7ac19047e3edd6347adff9d0..19f1e105779aa18d3de89695d76c23f37fa12c92 100644 (file)
@@ -928,15 +928,17 @@ void radv_GetPhysicalDeviceMemoryProperties(
        };
 
        STATIC_ASSERT(RADV_MEM_HEAP_COUNT <= VK_MAX_MEMORY_HEAPS);
+       uint64_t visible_vram_size = MIN2(physical_device->rad_info.vram_size,
+                                         physical_device->rad_info.vram_vis_size);
 
        pMemoryProperties->memoryHeapCount = RADV_MEM_HEAP_COUNT;
        pMemoryProperties->memoryHeaps[RADV_MEM_HEAP_VRAM] = (VkMemoryHeap) {
                .size = physical_device->rad_info.vram_size -
-                               physical_device->rad_info.vram_vis_size,
+                               visible_vram_size,
                .flags = VK_MEMORY_HEAP_DEVICE_LOCAL_BIT,
        };
        pMemoryProperties->memoryHeaps[RADV_MEM_HEAP_VRAM_CPU_ACCESS] = (VkMemoryHeap) {
-               .size = physical_device->rad_info.vram_vis_size,
+               .size = visible_vram_size,
                .flags = VK_MEMORY_HEAP_DEVICE_LOCAL_BIT,
        };
        pMemoryProperties->memoryHeaps[RADV_MEM_HEAP_GTT] = (VkMemoryHeap) {