本文整理汇总了C++中VkLayerDispatchTable::AllocateMemory方法的典型用法代码示例。如果您正苦于以下问题:C++ VkLayerDispatchTable::AllocateMemory方法的具体用法?C++ VkLayerDispatchTable::AllocateMemory怎么用?C++ VkLayerDispatchTable::AllocateMemory使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类VkLayerDispatchTable
的用法示例。
在下文中一共展示了VkLayerDispatchTable::AllocateMemory方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: vkGetSwapchainImagesKHR
//.........这里部分代码省略.........
ivci.format = data->format;
ivci.components.r = VK_COMPONENT_SWIZZLE_R;
ivci.components.g = VK_COMPONENT_SWIZZLE_G;
ivci.components.b = VK_COMPONENT_SWIZZLE_B;
ivci.components.a = VK_COMPONENT_SWIZZLE_A;
ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
ivci.subresourceRange.baseMipLevel = 0;
ivci.subresourceRange.levelCount = 1;
ivci.subresourceRange.baseArrayLayer = 0;
ivci.subresourceRange.layerCount = 1;
ivci.image = pImages[i];
ivci.flags = 0;
VkImageView v;
pTable->CreateImageView(device, &ivci, nullptr, &v);
/* Create framebuffer for each */
VkFramebufferCreateInfo fci;
fci.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
fci.pNext = nullptr;
fci.flags = 0;
fci.renderPass = data->render_pass;
fci.attachmentCount = 1;
fci.pAttachments = &v;
fci.width = data->width;
fci.height = data->height;
fci.layers = 1;
VkFramebuffer fb;
pTable->CreateFramebuffer(device, &fci, nullptr, &fb);
/* Create command buffer for each */
VkCommandBufferAllocateInfo cbai;
cbai.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
cbai.pNext = nullptr;
cbai.commandPool = my_data->pool;
cbai.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
cbai.commandBufferCount = 1;
VkCommandBuffer cmd;
pTable->AllocateCommandBuffers(device, &cbai, &cmd);
/* We have just created a dispatchable object, but the dispatch
* table has not been placed in the object yet.
* When a "normal" application creates a command buffer,
* the dispatch table is installed by the top-level binding
* (trampoline.c).
* But here, we have to do it ourselves. */
if (!my_data->pfn_dev_init) {
*((const void **)cmd) = *(void **)device;
} else {
err = my_data->pfn_dev_init(device, (void *)cmd);
assert(!err);
}
/* Create vertex buffer */
VkBufferCreateInfo bci;
memset(&bci, 0, sizeof(bci));
bci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
bci.usage = VK_BUFFER_USAGE_VERTEX_BUFFER_BIT;
bci.size = sizeof(vertex) * MAX_TEXT_VERTICES;
VkBuffer buf;
err = pTable->CreateBuffer(device, &bci, nullptr, &buf);
assert(!err);
VkMemoryRequirements mem_reqs;
pTable->GetBufferMemoryRequirements(device, buf, &mem_reqs);
assert(!err);
VkMemoryAllocateInfo mem_alloc;
memset(&mem_alloc, 0, sizeof(mem_alloc));
mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
mem_alloc.allocationSize = mem_reqs.size;
mem_alloc.memoryTypeIndex = choose_memory_type(
my_data->gpu, mem_reqs.memoryTypeBits, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
VkDeviceMemory mem;
err = pTable->AllocateMemory(device, &mem_alloc, nullptr, &mem);
assert(!err);
err = pTable->BindBufferMemory(device, buf, mem, 0);
assert(!err);
auto imageData = new WsiImageData;
imageData->image = pImages[i];
imageData->view = v;
imageData->framebuffer = fb;
imageData->cmd = cmd;
imageData->vertexBuffer = buf;
imageData->vertexBufferMemory = mem;
imageData->numVertices = 0;
imageData->vertexBufferSize = mem_alloc.allocationSize;
data->presentableImages.push_back(imageData);
}
}
return result;
}
示例2: writePPM
//.........这里部分代码省略.........
// If we need both images, set up image2 to be read/write and tiled.
if (need2steps) {
imgCreateInfo2.tiling = VK_IMAGE_TILING_OPTIMAL;
imgCreateInfo2.usage =
VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
}
VkMemoryAllocateInfo memAllocInfo = {
VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO, NULL,
0, // allocationSize, queried later
0 // memoryTypeIndex, queried later
};
VkMemoryRequirements memRequirements;
VkPhysicalDeviceMemoryProperties memoryProperties;
// Create image2 and allocate its memory. It could be the intermediate or
// final image.
err =
pTableDevice->CreateImage(device, &imgCreateInfo2, NULL, &data.image2);
assert(!err);
if (VK_SUCCESS != err)
return;
pTableDevice->GetImageMemoryRequirements(device, data.image2,
&memRequirements);
memAllocInfo.allocationSize = memRequirements.size;
pInstanceTable->GetPhysicalDeviceMemoryProperties(physicalDevice,
&memoryProperties);
pass = memory_type_from_properties(
&memoryProperties, memRequirements.memoryTypeBits,
need2steps ? VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT
: VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT,
&memAllocInfo.memoryTypeIndex);
assert(pass);
err = pTableDevice->AllocateMemory(device, &memAllocInfo, NULL, &data.mem2);
assert(!err);
if (VK_SUCCESS != err)
return;
err = pTableQueue->BindImageMemory(device, data.image2, data.mem2, 0);
assert(!err);
if (VK_SUCCESS != err)
return;
// Create image3 and allocate its memory, if needed.
if (need2steps) {
err = pTableDevice->CreateImage(device, &imgCreateInfo3, NULL,
&data.image3);
assert(!err);
if (VK_SUCCESS != err)
return;
pTableDevice->GetImageMemoryRequirements(device, data.image3,
&memRequirements);
memAllocInfo.allocationSize = memRequirements.size;
pInstanceTable->GetPhysicalDeviceMemoryProperties(physicalDevice,
&memoryProperties);
pass = memory_type_from_properties(
&memoryProperties, memRequirements.memoryTypeBits,
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT, &memAllocInfo.memoryTypeIndex);
assert(pass);
err = pTableDevice->AllocateMemory(device, &memAllocInfo, NULL,
&data.mem3);
assert(!err);
if (VK_SUCCESS != err)
return;
err = pTableQueue->BindImageMemory(device, data.image3, data.mem3, 0);
assert(!err);
if (VK_SUCCESS != err)
示例3: after_device_create
static void after_device_create(VkPhysicalDevice gpu, VkDevice device, layer_data *data) {
VkResult U_ASSERT_ONLY err;
data->gpu = gpu;
data->dev = device;
data->frame = 0;
data->cmdBuffersThisFrame = 0;
VkLayerDispatchTable *pTable = data->device_dispatch_table;
/* Get our WSI hooks in. */
data->pfnCreateSwapchainKHR = (PFN_vkCreateSwapchainKHR)pTable->GetDeviceProcAddr(device, "vkCreateSwapchainKHR");
data->pfnGetSwapchainImagesKHR = (PFN_vkGetSwapchainImagesKHR)pTable->GetDeviceProcAddr(device, "vkGetSwapchainImagesKHR");
data->pfnQueuePresentKHR = (PFN_vkQueuePresentKHR)pTable->GetDeviceProcAddr(device, "vkQueuePresentKHR");
data->pfnDestroySwapchainKHR = (PFN_vkDestroySwapchainKHR)pTable->GetDeviceProcAddr(device, "vkDestroySwapchainKHR");
data->swapChains = new std::unordered_map<VkSwapchainKHR, SwapChainData *>;
/* Command pool */
VkCommandPoolCreateInfo cpci;
cpci.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
cpci.pNext = nullptr;
cpci.queueFamilyIndex = data->graphicsQueueFamilyIndex;
cpci.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
err = pTable->CreateCommandPool(device, &cpci, nullptr, &data->pool);
assert(!err);
/* Create the objects we need */
/* Compile the shaders */
compile_shader(device, VULKAN_SAMPLES_BASE_DIR "/Layer-Samples/data/overlay-vert.spv", &data->vsShaderModule);
compile_shader(device, VULKAN_SAMPLES_BASE_DIR "/Layer-Samples/data/overlay-frag.spv", &data->fsShaderModule);
/* Upload the font bitmap */
VkImageCreateInfo ici;
memset(&ici, 0, sizeof(ici));
ici.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
ici.imageType = VK_IMAGE_TYPE_2D;
ici.format = VK_FORMAT_R8_UNORM;
ici.extent.width = FONT_ATLAS_SIZE;
ici.extent.height = FONT_ATLAS_SIZE;
ici.extent.depth = 1;
ici.mipLevels = 1;
ici.arrayLayers = 1;
ici.samples = VK_SAMPLE_COUNT_1_BIT;
ici.tiling = VK_IMAGE_TILING_LINEAR;
ici.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
ici.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
err = pTable->CreateImage(device, &ici, nullptr, &data->fontGlyphsImage);
assert(!err);
VkMemoryRequirements mem_reqs;
pTable->GetImageMemoryRequirements(device, data->fontGlyphsImage, &mem_reqs);
VkMemoryAllocateInfo mem_alloc;
memset(&mem_alloc, 0, sizeof(mem_alloc));
mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
mem_alloc.allocationSize = mem_reqs.size;
mem_alloc.memoryTypeIndex = choose_memory_type(gpu, mem_reqs.memoryTypeBits,
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
err = pTable->AllocateMemory(device, &mem_alloc, nullptr, &data->fontGlyphsMemory);
assert(!err);
err = pTable->BindImageMemory(device, data->fontGlyphsImage, data->fontGlyphsMemory, 0);
assert(!err);
VkImageSubresource subres;
subres.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
subres.mipLevel = 0;
subres.arrayLayer = 0;
VkSubresourceLayout layout;
void *bits;
pTable->GetImageSubresourceLayout(device, data->fontGlyphsImage, &subres, &layout);
/* ensure we can directly upload into this layout */
assert(!layout.offset);
assert(layout.size >= FONT_ATLAS_SIZE * FONT_ATLAS_SIZE);
assert(layout.rowPitch == FONT_ATLAS_SIZE);
err = pTable->MapMemory(device, data->fontGlyphsMemory, 0, VK_WHOLE_SIZE, 0, &bits);
assert(!err);
/* Load the font glyphs directly into the mapped buffer */
std::vector<unsigned char> fontData;
get_file_contents(VULKAN_SAMPLES_BASE_DIR "/Layer-Samples/data/FreeSans.ttf", fontData);
stbtt_BakeFontBitmap(&fontData[0], 0, FONT_SIZE_PIXELS, (unsigned char *)bits, FONT_ATLAS_SIZE, FONT_ATLAS_SIZE, 32, 96,
data->glyphs);
pTable->UnmapMemory(device, data->fontGlyphsMemory);
VkImageViewCreateInfo ivci;
ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
ivci.pNext = nullptr;
ivci.format = ici.format;
ivci.components.r = VK_COMPONENT_SWIZZLE_R;
ivci.components.g = VK_COMPONENT_SWIZZLE_G;
ivci.components.b = VK_COMPONENT_SWIZZLE_B;
ivci.components.a = VK_COMPONENT_SWIZZLE_A;
//.........这里部分代码省略.........