diff --git a/examples/occlusionquery/occlusionquery.cpp b/examples/occlusionquery/occlusionquery.cpp index 3be49e6..23fe127 100644 --- a/examples/occlusionquery/occlusionquery.cpp +++ b/examples/occlusionquery/occlusionquery.cpp @@ -120,19 +120,20 @@ public: VkQueryPoolCreateInfo queryPoolInfo = {}; queryPoolInfo.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO; queryPoolInfo.queryType = VK_QUERY_TYPE_OCCLUSION; - queryPoolInfo.queryCount = 2; + queryPoolInfo.queryCount = 128; VK_CHECK_RESULT(vkCreateQueryPool(device, &queryPoolInfo, NULL, &queryPool)); } // Retrieves the results of the occlusion queries submitted to the command buffer void getQueryResults() { - // We use vkGetQueryResults to copy the results into a host visible buffer + vkDeviceWaitIdle(device); + vkGetQueryPoolResults( device, queryPool, 0, - 2, + 1, sizeof(passedSamples), passedSamples, sizeof(uint64_t), @@ -166,12 +167,6 @@ public: VK_CHECK_RESULT(vkBeginCommandBuffer(drawCmdBuffers[i], &cmdBufInfo)); - // Reset query pool - // Must be done outside of render pass - vkCmdResetQueryPool(drawCmdBuffers[i], queryPool, 0, 2); - - vkCmdBeginRenderPass(drawCmdBuffers[i], &renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE); - VkViewport viewport = vks::initializers::viewport( (float)width, (float)height, @@ -190,6 +185,12 @@ public: glm::mat4 modelMatrix = glm::mat4(1.0f); + // Reset query pool + // Must be done outside of render pass + vkCmdResetQueryPool(drawCmdBuffers[i], queryPool, 0, 128); + vkCmdBeginQuery(drawCmdBuffers[i], queryPool, 0, VK_FLAGS_NONE); + vkCmdBeginRenderPass(drawCmdBuffers[i], &renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE); + // Occlusion pass vkCmdBindPipeline(drawCmdBuffers[i], VK_PIPELINE_BIND_POINT_GRAPHICS, pipelines.simple); @@ -200,48 +201,23 @@ public: vkCmdDrawIndexed(drawCmdBuffers[i], models.plane.indexCount, 1, 0, 0, 0); // Teapot - vkCmdBeginQuery(drawCmdBuffers[i], queryPool, 0, VK_FLAGS_NONE); vkCmdBindDescriptorSets(drawCmdBuffers[i], VK_PIPELINE_BIND_POINT_GRAPHICS, pipelineLayout, 0, 1, &descriptorSets.teapot, 0, NULL); vkCmdBindVertexBuffers(drawCmdBuffers[i], VERTEX_BUFFER_BIND_ID, 1, &models.teapot.vertices.buffer, offsets); vkCmdBindIndexBuffer(drawCmdBuffers[i], models.teapot.indices.buffer, 0, VK_INDEX_TYPE_UINT32); vkCmdDrawIndexed(drawCmdBuffers[i], models.teapot.indexCount, 1, 0, 0, 0); - vkCmdEndQuery(drawCmdBuffers[i], queryPool, 0); - // Sphere - vkCmdBeginQuery(drawCmdBuffers[i], queryPool, 1, VK_FLAGS_NONE); - vkCmdBindDescriptorSets(drawCmdBuffers[i], VK_PIPELINE_BIND_POINT_GRAPHICS, pipelineLayout, 0, 1, &descriptorSets.sphere, 0, NULL); vkCmdBindVertexBuffers(drawCmdBuffers[i], VERTEX_BUFFER_BIND_ID, 1, &models.sphere.vertices.buffer, offsets); vkCmdBindIndexBuffer(drawCmdBuffers[i], models.sphere.indices.buffer, 0, VK_INDEX_TYPE_UINT32); vkCmdDrawIndexed(drawCmdBuffers[i], models.sphere.indexCount, 1, 0, 0, 0); - vkCmdEndQuery(drawCmdBuffers[i], queryPool, 1); + vkCmdEndRenderPass(drawCmdBuffers[i]); + vkCmdEndQuery(drawCmdBuffers[i], queryPool, 0); // Visible pass - // Clear color and depth attachments - VkClearAttachment clearAttachments[2] = {}; - - clearAttachments[0].aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; - clearAttachments[0].clearValue.color = defaultClearColor; - clearAttachments[0].colorAttachment = 0; - - clearAttachments[1].aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT; - clearAttachments[1].clearValue.depthStencil = { 1.0f, 0 }; - - VkClearRect clearRect = {}; - clearRect.layerCount = 1; - clearRect.rect.offset = { 0, 0 }; - clearRect.rect.extent = { width, height }; - - vkCmdClearAttachments( - drawCmdBuffers[i], - 2, - clearAttachments, - 1, - &clearRect); - + vkCmdBeginRenderPass(drawCmdBuffers[i], &renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE); vkCmdBindPipeline(drawCmdBuffers[i], VK_PIPELINE_BIND_POINT_GRAPHICS, pipelines.solid); // Teapot @@ -278,9 +254,9 @@ public: VK_CHECK_RESULT(vkQueueSubmit(queue, 1, &submitInfo, VK_NULL_HANDLE)); // Read query results for displaying in next frame - getQueryResults(); - VulkanExampleBase::submitFrame(); + + getQueryResults(); } void loadAssets() @@ -607,4 +583,4 @@ public: }; -VULKAN_EXAMPLE_MAIN() \ No newline at end of file +VULKAN_EXAMPLE_MAIN()