• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.adoc[]
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.adoc[]
34
35=== Examples
36
37[source,c++]
38----
39    // Create an image with
40    // VkDedicatedAllocationImageCreateInfoNV::dedicatedAllocation
41    // set to VK_TRUE
42
43    VkDedicatedAllocationImageCreateInfoNV dedicatedImageInfo =
44    {
45        .sType = VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_IMAGE_CREATE_INFO_NV,
46        .pNext = NULL,
47        .dedicatedAllocation = VK_TRUE,
48    };
49
50    VkImageCreateInfo imageCreateInfo =
51    {
52        .sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,
53        .pNext = &dedicatedImageInfo
54        // Other members set as usual
55    };
56
57    VkImage image;
58    VkResult result = vkCreateImage(
59        device,
60        &imageCreateInfo,
61        NULL,               // pAllocator
62        &image);
63
64    VkMemoryRequirements memoryRequirements;
65    vkGetImageMemoryRequirements(
66        device,
67        image,
68        &memoryRequirements);
69
70    // Allocate memory with VkDedicatedAllocationMemoryAllocateInfoNV::image
71    // pointing to the image we are allocating the memory for
72
73    VkDedicatedAllocationMemoryAllocateInfoNV dedicatedInfo =
74    {
75        .sType = VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_MEMORY_ALLOCATE_INFO_NV,
76        .pNext = NULL,
77        .image = image,
78        .buffer = VK_NULL_HANDLE,
79    };
80
81    VkMemoryAllocateInfo memoryAllocateInfo =
82    {
83        .sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO,
84        .pNext = &dedicatedInfo,
85        .allocationSize = memoryRequirements.size,
86        .memoryTypeIndex = FindMemoryTypeIndex(memoryRequirements.memoryTypeBits),
87    };
88
89    VkDeviceMemory memory;
90    vkAllocateMemory(
91        device,
92        &memoryAllocateInfo,
93        NULL,               // pAllocator
94        &memory);
95
96    // Bind the image to the memory
97
98    vkBindImageMemory(
99        device,
100        image,
101        memory,
102        0);
103----
104
105=== Version History
106
107  * Revision 1, 2016-05-31 (Jeff Bolz)
108  ** Internal revisions
109