本文整理汇总了C++中VkLayerDispatchTable::CmdPipelineBarrier方法的典型用法代码示例。如果您正苦于以下问题:C++ VkLayerDispatchTable::CmdPipelineBarrier方法的具体用法?C++ VkLayerDispatchTable::CmdPipelineBarrier怎么用?C++ VkLayerDispatchTable::CmdPipelineBarrier使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类VkLayerDispatchTable
的用法示例。
在下文中一共展示了VkLayerDispatchTable::CmdPipelineBarrier方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: before_present
static void before_present(VkQueue queue, layer_data *my_data, SwapChainData *swapChain, unsigned imageIndex) {
VkLayerDispatchTable *pTable = my_data->device_dispatch_table;
if (!my_data->fontUploadComplete) {
VkSubmitInfo si = {};
si.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
si.pNext = nullptr;
si.waitSemaphoreCount = 0;
si.commandBufferCount = 1;
si.signalSemaphoreCount = 0;
si.pCommandBuffers = &my_data->fontUploadCmdBuffer;
pTable->QueueSubmit(queue, 1, &si, VK_NULL_HANDLE);
my_data->fontUploadComplete = true;
#ifdef OVERLAY_DEBUG
printf("Font image layout transition queued\n");
#endif
}
WsiImageData *id = swapChain->presentableImages[imageIndex];
/* update the overlay content */
vertex *vertices = nullptr;
/* guaranteed not in flight due to WSI surface being available */
VkResult U_ASSERT_ONLY err =
pTable->MapMemory(my_data->dev, id->vertexBufferMemory, 0, id->vertexBufferSize, 0, (void **)&vertices);
assert(!err);
/* write vertices for string in here */
id->numVertices = fill_vertex_buffer(my_data, vertices, imageIndex);
pTable->UnmapMemory(my_data->dev, id->vertexBufferMemory);
/* JIT record a command buffer to draw the overlay */
VkCommandBufferBeginInfo cbbi;
cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
cbbi.pNext = nullptr;
cbbi.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
cbbi.pInheritanceInfo = nullptr;
VkImageMemoryBarrier imb;
imb.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
imb.pNext = nullptr;
imb.dstAccessMask = VK_ACCESS_MEMORY_READ_BIT;
imb.srcAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
imb.oldLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
imb.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
imb.image = id->image;
imb.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
imb.subresourceRange.baseMipLevel = 0;
imb.subresourceRange.levelCount = 1;
imb.subresourceRange.baseArrayLayer = 0;
imb.subresourceRange.layerCount = 1;
imb.srcQueueFamilyIndex = my_data->graphicsQueueFamilyIndex;
imb.dstQueueFamilyIndex = my_data->graphicsQueueFamilyIndex;
VkRenderPassBeginInfo rpbi;
rpbi.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
rpbi.pNext = nullptr;
rpbi.renderPass = swapChain->render_pass;
rpbi.framebuffer = id->framebuffer;
rpbi.renderArea.offset.x = 0;
rpbi.renderArea.offset.y = 0;
rpbi.renderArea.extent.width = swapChain->width;
rpbi.renderArea.extent.height = swapChain->height;
rpbi.clearValueCount = 0;
rpbi.pClearValues = nullptr;
pTable->BeginCommandBuffer(id->cmd, &cbbi);
pTable->CmdPipelineBarrier(id->cmd, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT,
0 /* dependency flags */, 0, nullptr, /* memory barriers */
0, nullptr, /* buffer memory barriers */
1, &imb); /* image memory barriers */
pTable->CmdBeginRenderPass(id->cmd, &rpbi, VK_SUBPASS_CONTENTS_INLINE);
pTable->CmdBindPipeline(id->cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, swapChain->pipeline);
pTable->CmdBindDescriptorSets(id->cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, my_data->pl, 0, 1, &my_data->desc_set, 0, nullptr);
VkDeviceSize offsets[] = {0};
VkBuffer buffers[] = {id->vertexBuffer};
pTable->CmdBindVertexBuffers(id->cmd, 0, 1, buffers, offsets);
pTable->CmdDraw(id->cmd, id->numVertices, 1, 0, 0);
pTable->CmdEndRenderPass(id->cmd);
pTable->EndCommandBuffer(id->cmd);
/* Schedule this command buffer for execution. TODO: Do we need to protect
* ourselves from an app that didn't wait for the presentation image to
* be idle before mangling it? If the app is well-behaved, our command
* buffer is guaranteed to have been retired before the app tries to
* present it again.
*/
VkSubmitInfo si = {};
si.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
si.pNext = nullptr;
//.........这里部分代码省略.........
示例2: writePPM
//.........这里部分代码省略.........
// This barrier is used to transition from a newly-created layout to a blt
// or copy destination layout.
VkImageMemoryBarrier destMemoryBarrier = {
VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,
NULL,
0,
VK_ACCESS_TRANSFER_WRITE_BIT,
VK_IMAGE_LAYOUT_UNDEFINED,
VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
VK_QUEUE_FAMILY_IGNORED,
VK_QUEUE_FAMILY_IGNORED,
data.image2,
{VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1}};
// This barrier is used to transition a dest layout to general layout.
VkImageMemoryBarrier generalMemoryBarrier = {
VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,
NULL,
VK_ACCESS_TRANSFER_WRITE_BIT,
VK_ACCESS_TRANSFER_READ_BIT,
VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
VK_IMAGE_LAYOUT_GENERAL,
VK_QUEUE_FAMILY_IGNORED,
VK_QUEUE_FAMILY_IGNORED,
data.image2,
{VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1}};
VkPipelineStageFlags srcStages = VK_PIPELINE_STAGE_TRANSFER_BIT;
VkPipelineStageFlags dstStages = VK_PIPELINE_STAGE_TRANSFER_BIT;
// The source image needs to be transitioned from present to transfer
// source.
pTableCommandBuffer->CmdPipelineBarrier(data.commandBuffer, srcStages,
dstStages, 0, 0, NULL, 0, NULL, 1,
&presentMemoryBarrier);
// image2 needs to be transitioned from its undefined state to transfer
// destination.
pTableCommandBuffer->CmdPipelineBarrier(data.commandBuffer, srcStages,
dstStages, 0, 0, NULL, 0, NULL, 1,
&destMemoryBarrier);
const VkImageCopy imageCopyRegion = {{VK_IMAGE_ASPECT_COLOR_BIT, 0, 0, 1},
{0, 0, 0},
{VK_IMAGE_ASPECT_COLOR_BIT, 0, 0, 1},
{0, 0, 0},
{width, height, 1}};
if (copyOnly) {
pTableCommandBuffer->CmdCopyImage(
data.commandBuffer, image1, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
data.image2, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
&imageCopyRegion);
} else {
VkImageBlit imageBlitRegion = {};
imageBlitRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
imageBlitRegion.srcSubresource.baseArrayLayer = 0;
imageBlitRegion.srcSubresource.layerCount = 1;
imageBlitRegion.srcSubresource.mipLevel = 0;
imageBlitRegion.srcOffsets[1].x = width;
imageBlitRegion.srcOffsets[1].y = height;
imageBlitRegion.srcOffsets[1].z = 1;
imageBlitRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
imageBlitRegion.dstSubresource.baseArrayLayer = 0;
imageBlitRegion.dstSubresource.layerCount = 1;
示例3: after_device_create
//.........这里部分代码省略.........
* But here, we have to do it ourselves. */
if (!data->pfn_dev_init) {
*((const void **)cmd) = *(void **)device;
} else {
err = data->pfn_dev_init(device, (void *)cmd);
assert(!err);
}
VkCommandBufferBeginInfo cbbi;
cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
cbbi.pNext = nullptr;
cbbi.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
cbbi.pInheritanceInfo = nullptr;
err = pTable->BeginCommandBuffer(cmd, &cbbi);
assert(!err);
VkImageMemoryBarrier imb;
imb.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
imb.pNext = nullptr;
imb.dstAccessMask = VK_ACCESS_HOST_WRITE_BIT | VK_ACCESS_TRANSFER_WRITE_BIT;
imb.srcAccessMask = 0;
imb.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
imb.newLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
imb.image = data->fontGlyphsImage;
imb.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
imb.subresourceRange.baseMipLevel = 0;
imb.subresourceRange.levelCount = 1;
imb.subresourceRange.baseArrayLayer = 0;
imb.subresourceRange.layerCount = 1;
imb.srcQueueFamilyIndex = data->graphicsQueueFamilyIndex;
imb.dstQueueFamilyIndex = data->graphicsQueueFamilyIndex;
pTable->CmdPipelineBarrier(cmd, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, 0 /* dependency flags */,
0, nullptr, /* memory barriers */
0, nullptr, /* buffer memory barriers */
1, &imb); /* image memory barriers */
pTable->EndCommandBuffer(cmd);
data->fontUploadCmdBuffer = cmd;
data->fontUploadComplete = false; /* we will schedule this at first present on this device */
#ifdef OVERLAY_DEBUG
printf("Font upload done.\n");
#endif
/* create a sampler to use with the texture */
VkSamplerCreateInfo sci;
sci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
sci.pNext = nullptr;
sci.flags = 0;
sci.magFilter = VK_FILTER_NEAREST;
sci.minFilter = VK_FILTER_NEAREST;
sci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
sci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
sci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
sci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
sci.mipLodBias = 0.0f;
sci.anisotropyEnable = false;
sci.maxAnisotropy = 1;
sci.compareEnable = false;
sci.compareOp = VK_COMPARE_OP_NEVER;
sci.minLod = 0.0f;
sci.maxLod = 0.0f;
sci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
sci.unnormalizedCoordinates = VK_FALSE;