1// Copyright (c) 2016-2020 NVIDIA Corporation 2// 3// SPDX-License-Identifier: CC-BY-4.0 4 5include::{generated}/meta/{refprefix}VK_NV_dedicated_allocation.txt[] 6 7=== Other Extension Metadata 8 9*Last Modified Date*:: 10 2016-05-31 11*IP Status*:: 12 No known IP claims. 13*Contributors*:: 14 - Jeff Bolz, NVIDIA 15 16=== Description 17 18This extension allows device memory to be allocated for a particular buffer 19or image resource, which on some devices can significantly improve the 20performance of that resource. 21Normal device memory allocations must support memory aliasing and sparse 22binding, which could interfere with optimizations like framebuffer 23compression or efficient page table usage. 24This is important for render targets and very large resources, but need not 25(and probably should not) be used for smaller resources that can benefit 26from suballocation. 27 28This extension adds a few small structures to resource creation and memory 29allocation: a new structure that flags whether am image/buffer will have a 30dedicated allocation, and a structure indicating the image or buffer that an 31allocation will be bound to. 32 33include::{generated}/interfaces/VK_NV_dedicated_allocation.txt[] 34 35=== Examples 36 37[source,c++] 38-------------------------------------- 39 40 // Create an image with 41 // VkDedicatedAllocationImageCreateInfoNV::dedicatedAllocation 42 // set to VK_TRUE 43 44 VkDedicatedAllocationImageCreateInfoNV dedicatedImageInfo = 45 { 46 VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_IMAGE_CREATE_INFO_NV, // sType 47 NULL, // pNext 48 VK_TRUE, // dedicatedAllocation 49 }; 50 51 VkImageCreateInfo imageCreateInfo = 52 { 53 VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO, // sType 54 &dedicatedImageInfo // pNext 55 // Other members set as usual 56 }; 57 58 VkImage image; 59 VkResult result = vkCreateImage( 60 device, 61 &imageCreateInfo, 62 NULL, // pAllocator 63 &image); 64 65 VkMemoryRequirements memoryRequirements; 66 vkGetImageMemoryRequirements( 67 device, 68 image, 69 &memoryRequirements); 70 71 // Allocate memory with VkDedicatedAllocationMemoryAllocateInfoNV::image 72 // pointing to the image we are allocating the memory for 73 74 VkDedicatedAllocationMemoryAllocateInfoNV dedicatedInfo = 75 { 76 VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_MEMORY_ALLOCATE_INFO_NV, // sType 77 NULL, // pNext 78 image, // image 79 VK_NULL_HANDLE, // buffer 80 }; 81 82 VkMemoryAllocateInfo memoryAllocateInfo = 83 { 84 VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO, // sType 85 &dedicatedInfo, // pNext 86 memoryRequirements.size, // allocationSize 87 FindMemoryTypeIndex(memoryRequirements.memoryTypeBits), // memoryTypeIndex 88 }; 89 90 VkDeviceMemory memory; 91 vkAllocateMemory( 92 device, 93 &memoryAllocateInfo, 94 NULL, // pAllocator 95 &memory); 96 97 // Bind the image to the memory 98 99 vkBindImageMemory( 100 device, 101 image, 102 memory, 103 0); 104 105-------------------------------------- 106 107=== Version History 108 109 * Revision 1, 2016-05-31 (Jeff Bolz) 110 - Internal revisions 111