当前位置: 首页>>代码示例>>C++>>正文


C++ VkLayerDispatchTable::BeginCommandBuffer方法代码示例

本文整理汇总了C++中VkLayerDispatchTable::BeginCommandBuffer方法的典型用法代码示例。如果您正苦于以下问题:C++ VkLayerDispatchTable::BeginCommandBuffer方法的具体用法?C++ VkLayerDispatchTable::BeginCommandBuffer怎么用?C++ VkLayerDispatchTable::BeginCommandBuffer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在VkLayerDispatchTable的用法示例。


在下文中一共展示了VkLayerDispatchTable::BeginCommandBuffer方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: writePPM


//.........这里部分代码省略.........
    // Set up the command buffer.  We get a command buffer from a pool we saved
    // in a hooked function, which would be the application's pool.
    const VkCommandBufferAllocateInfo allocCommandBufferInfo = {
        VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, NULL,
        deviceMap[device]->commandPool, VK_COMMAND_BUFFER_LEVEL_PRIMARY, 1};
    data.commandPool = deviceMap[device]->commandPool;
    err = pTableDevice->AllocateCommandBuffers(device, &allocCommandBufferInfo,
                                               &data.commandBuffer);
    assert(!err);
    if (VK_SUCCESS != err)
        return;

    VkDevice cmdBuf =
        static_cast<VkDevice>(static_cast<void *>(data.commandBuffer));
    deviceMap.emplace(cmdBuf, devMap);
    VkLayerDispatchTable *pTableCommandBuffer;
    pTableCommandBuffer = get_dev_info(cmdBuf)->device_dispatch_table;

    // 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 api
    // binding (trampoline.c). But here, we have to do it ourselves.
    if (!devMap->pfn_dev_init) {
        *((const void **)data.commandBuffer) = *(void **)device;
    } else {
        err = devMap->pfn_dev_init(device, (void *)data.commandBuffer);
        assert(!err);
    }

    const VkCommandBufferBeginInfo commandBufferBeginInfo = {
        VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, NULL,
        VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT,
    };
    err = pTableCommandBuffer->BeginCommandBuffer(data.commandBuffer,
                                                  &commandBufferBeginInfo);
    assert(!err);

    // This barrier is used to transition from/to present Layout
    VkImageMemoryBarrier presentMemoryBarrier = {
        VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,
        NULL,
        VK_ACCESS_TRANSFER_WRITE_BIT,
        VK_ACCESS_TRANSFER_READ_BIT,
        VK_IMAGE_LAYOUT_PRESENT_SRC_KHR,
        VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
        VK_QUEUE_FAMILY_IGNORED,
        VK_QUEUE_FAMILY_IGNORED,
        image1,
        {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1}};

    // 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 = {
开发者ID:ZLixing,项目名称:VulkanTools,代码行数:67,代码来源:screenshot.cpp

示例2: 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;
//.........这里部分代码省略.........
开发者ID:LunarG,项目名称:VulkanSamples,代码行数:101,代码来源:overlay.cpp

示例3: after_device_create


//.........这里部分代码省略.........
    assert(!err);

    /* transition from undefined layout to shader readonly so we can use it.
     * requires a command buffer. */
    VkCommandBufferAllocateInfo cbai;
    cbai.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
    cbai.pNext = nullptr;
    cbai.commandPool = data->pool;
    cbai.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
    cbai.commandBufferCount = 1;

    VkCommandBuffer cmd;
    err = pTable->AllocateCommandBuffers(device, &cbai, &cmd);
    assert(!err);

    /* 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 (!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 */
开发者ID:LunarG,项目名称:VulkanSamples,代码行数:67,代码来源:overlay.cpp

示例4: vkQueuePresentKHR

VkResult WrappedVulkan::vkQueuePresentKHR(
			VkQueue                                      queue,
			const VkPresentInfoKHR*                      pPresentInfo)
{
	if(m_State == WRITING_IDLE)
	{
		RenderDoc::Inst().Tick();

		GetResourceManager()->FlushPendingDirty();
	}
	
	m_FrameCounter++; // first present becomes frame #1, this function is at the end of the frame

	if(pPresentInfo->swapchainCount > 1 && (m_FrameCounter % 100) == 0)
	{
		RDCWARN("Presenting multiple swapchains at once - only first will be processed");
	}
	
	vector<VkSwapchainKHR> unwrappedSwaps;
	vector<VkSemaphore> unwrappedSems;
	
	VkPresentInfoKHR unwrappedInfo = *pPresentInfo;

	for(uint32_t i=0; i < unwrappedInfo.swapchainCount; i++)
		unwrappedSwaps.push_back(Unwrap(unwrappedInfo.pSwapchains[i]));
	for(uint32_t i=0; i < unwrappedInfo.waitSemaphoreCount; i++)
		unwrappedSems.push_back(Unwrap(unwrappedInfo.pWaitSemaphores[i]));

	unwrappedInfo.pSwapchains = unwrappedInfo.swapchainCount ? &unwrappedSwaps[0] : NULL;
	unwrappedInfo.pWaitSemaphores = unwrappedInfo.waitSemaphoreCount ? &unwrappedSems[0] : NULL;

	// Don't support any extensions for present info
	RDCASSERT(pPresentInfo->pNext == NULL);
	
	VkResourceRecord *swaprecord = GetRecord(pPresentInfo->pSwapchains[0]);
	RDCASSERT(swaprecord->swapInfo);

	SwapchainInfo &swapInfo = *swaprecord->swapInfo;

	bool activeWindow = RenderDoc::Inst().IsActiveWindow(LayerDisp(m_Instance), swapInfo.wndHandle);

	// need to record which image was last flipped so we can get the correct backbuffer
	// for a thumbnail in EndFrameCapture
	swapInfo.lastPresent = pPresentInfo->pImageIndices[0];
	m_LastSwap = swaprecord->GetResourceID();
	
	VkImage backbuffer = swapInfo.images[pPresentInfo->pImageIndices[0]].im;
	
	if(m_State == WRITING_IDLE)
	{
		m_FrameTimes.push_back(m_FrameTimer.GetMilliseconds());
		m_TotalTime += m_FrameTimes.back();
		m_FrameTimer.Restart();

		// update every second
		if(m_TotalTime > 1000.0)
		{
			m_MinFrametime = 10000.0;
			m_MaxFrametime = 0.0;
			m_AvgFrametime = 0.0;

			m_TotalTime = 0.0;

			for(size_t i=0; i < m_FrameTimes.size(); i++)
			{
				m_AvgFrametime += m_FrameTimes[i];
				if(m_FrameTimes[i] < m_MinFrametime)
					m_MinFrametime = m_FrameTimes[i];
				if(m_FrameTimes[i] > m_MaxFrametime)
					m_MaxFrametime = m_FrameTimes[i];
			}

			m_AvgFrametime /= double(m_FrameTimes.size());

			m_FrameTimes.clear();
		}
		
		uint32_t overlay = RenderDoc::Inst().GetOverlayBits();

		if(overlay & eRENDERDOC_Overlay_Enabled)
		{
			VkRenderPass rp = swapInfo.rp;
			VkImage im = swapInfo.images[pPresentInfo->pImageIndices[0]].im;
			VkFramebuffer fb = swapInfo.images[pPresentInfo->pImageIndices[0]].fb;

			VkLayerDispatchTable *vt = ObjDisp(GetDev());

			TextPrintState textstate = { GetNextCmd(), rp, fb, swapInfo.extent.width, swapInfo.extent.height };
			
			VkCommandBufferBeginInfo beginInfo = { VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, NULL, VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT };

			VkResult vkr = vt->BeginCommandBuffer(Unwrap(textstate.cmd), &beginInfo);
			RDCASSERTEQUAL(vkr, VK_SUCCESS);

			VkImageMemoryBarrier bbBarrier = {
				VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, NULL,
				0, 0, VK_IMAGE_LAYOUT_PRESENT_SRC_KHR, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
				VK_QUEUE_FAMILY_IGNORED, VK_QUEUE_FAMILY_IGNORED,
				Unwrap(im),
				{ VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 }
//.........这里部分代码省略.........
开发者ID:Althar93,项目名称:renderdoc,代码行数:101,代码来源:vk_wsi_funcs.cpp

示例5: 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;

    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->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.
     */
    VkFence null_fence = VK_NULL_HANDLE;
    VkSubmitInfo si;
    si.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
    si.pNext = nullptr;
    si.waitSemaphoreCount = 0;
    si.commandBufferCount = 1;
    si.signalSemaphoreCount = 0;
    si.pCommandBuffers = &id->cmd;
    pTable->QueueSubmit(queue, 1, &si, null_fence);

    /* Reset per-frame stats */
    my_data->cmdBuffersThisFrame = 0;
}
开发者ID:10imaging,项目名称:vulkan-basic-samples,代码行数:95,代码来源:overlay.cpp


注:本文中的VkLayerDispatchTable::BeginCommandBuffer方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。