From 18f41c6fb6852284e59523ad5538d4d0b8609eba Mon Sep 17 00:00:00 2001 From: baldurk Date: Fri, 7 Oct 2022 11:20:06 +0100 Subject: [PATCH] Add test of secondary command buffer dynamic rendering --- util/test/demos/vk/vk_dynamic_rendering.cpp | 36 ++++- .../test/tests/Vulkan/VK_Dynamic_Rendering.py | 129 ++++++++++-------- 2 files changed, 110 insertions(+), 55 deletions(-) diff --git a/util/test/demos/vk/vk_dynamic_rendering.cpp b/util/test/demos/vk/vk_dynamic_rendering.cpp index 72675ddfe..88e097c7d 100644 --- a/util/test/demos/vk/vk_dynamic_rendering.cpp +++ b/util/test/demos/vk/vk_dynamic_rendering.cpp @@ -272,15 +272,49 @@ void main() vkCmdPushConstants(cmd, layout, VK_SHADER_STAGE_ALL, 0, 4, &ssboIdx); + setMarker(cmd, "Draw 0"); + vkCmdDraw(cmd, 3, 1, 0, 0); vkCmdEndRenderingKHR(cmd); + VkCommandBuffer cmd2 = GetCommandBuffer(VK_COMMAND_BUFFER_LEVEL_SECONDARY); + + { + VkCommandBufferInheritanceInfo inherit = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO}; + + vkBeginCommandBuffer(cmd2, vkh::CommandBufferBeginInfo(0, &inherit)); + + vkCmdBeginRenderingKHR(cmd2, &rendInfo); + + VkViewport v = mainWindow->viewport; + v.width /= 2; + v.height /= 2; + + vkCmdBindPipeline(cmd2, VK_PIPELINE_BIND_POINT_GRAPHICS, pipe); + vkCmdSetViewport(cmd2, 0, 1, &v); + vkCmdSetScissor(cmd2, 0, 1, &mainWindow->scissor); + vkh::cmdBindVertexBuffers(cmd2, 0, {vb.buffer}, {0}); + vkh::cmdBindDescriptorSets(cmd2, VK_PIPELINE_BIND_POINT_GRAPHICS, layout, 0, {descset}, {}); + + vkCmdPushConstants(cmd2, layout, VK_SHADER_STAGE_ALL, 0, 4, &ssboIdx); + + setMarker(cmd2, "Draw 1"); + + vkCmdDraw(cmd2, 3, 1, 0, 0); + + vkCmdEndRenderingKHR(cmd2); + + vkEndCommandBuffer(cmd2); + } + + vkCmdExecuteCommands(cmd, 1, &cmd2); + FinishUsingBackbuffer(cmd, VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, VK_IMAGE_LAYOUT_GENERAL); vkEndCommandBuffer(cmd); - Submit(0, 1, {cmd}); + Submit(0, 1, {cmd}, {cmd2}); Present(); } diff --git a/util/test/tests/Vulkan/VK_Dynamic_Rendering.py b/util/test/tests/Vulkan/VK_Dynamic_Rendering.py index 691cc0ce2..215f2aac4 100644 --- a/util/test/tests/Vulkan/VK_Dynamic_Rendering.py +++ b/util/test/tests/Vulkan/VK_Dynamic_Rendering.py @@ -7,75 +7,96 @@ class VK_Dynamic_Rendering(rdtest.TestCase): demos_test_name = 'VK_Dynamic_Rendering' def check_capture(self): - action = self.find_action("Draw") + out: rd.ReplayOutput = self.controller.CreateOutput(rd.CreateHeadlessWindowingData(100, 100), + rd.ReplayOutputType.Texture) - self.check(action is not None) + for cmdLevel in [0,1]: + action = self.find_action("Draw {}".format(cmdLevel)).next - self.controller.SetFrameEvent(action.eventId, False) + self.check(action is not None) - postgs_data = self.get_postvs(action, rd.MeshDataStage.GSOut, 0, action.numIndices) + self.controller.SetFrameEvent(action.eventId, False) - postgs_ref = { - 0: { - 'vtx': 0, - 'idx': 0, - 'gl_PerVertex_var.gl_Position': [-0.5, 0.5, 0.0, 1.0], - 'gout.pos': [-0.5, 0.5, 0.0, 1.0], - 'gout.col': [0.0, 1.0, 0.0, 1.0], - 'gout.uv': [0.0, 0.0, 0.0, 1.0], - }, - 1: { - 'vtx': 1, - 'idx': 1, - 'gl_PerVertex_var.gl_Position': [0.0, -0.5, 0.0, 1.0], - 'gout.pos': [0.0, -0.5, 0.0, 1.0], - 'gout.col': [0.0, 1.0, 0.0, 1.0], - 'gout.uv': [0.0, 1.0, 0.0, 1.0], - }, - 2: { - 'vtx': 2, - 'idx': 2, - 'gl_PerVertex_var.gl_Position': [0.5, 0.5, 0.0, 1.0], - 'gout.pos': [0.5, 0.5, 0.0, 1.0], - 'gout.col': [0.0, 1.0, 0.0, 1.0], - 'gout.uv': [1.0, 0.0, 0.0, 1.0], - }, - } + postgs_data = self.get_postvs(action, rd.MeshDataStage.GSOut, 0, action.numIndices) - self.check_mesh_data(postgs_ref, postgs_data) + postgs_ref = { + 0: { + 'vtx': 0, + 'idx': 0, + 'gl_PerVertex_var.gl_Position': [-0.5, 0.5, 0.0, 1.0], + 'gout.pos': [-0.5, 0.5, 0.0, 1.0], + 'gout.col': [0.0, 1.0, 0.0, 1.0], + 'gout.uv': [0.0, 0.0, 0.0, 1.0], + }, + 1: { + 'vtx': 1, + 'idx': 1, + 'gl_PerVertex_var.gl_Position': [0.0, -0.5, 0.0, 1.0], + 'gout.pos': [0.0, -0.5, 0.0, 1.0], + 'gout.col': [0.0, 1.0, 0.0, 1.0], + 'gout.uv': [0.0, 1.0, 0.0, 1.0], + }, + 2: { + 'vtx': 2, + 'idx': 2, + 'gl_PerVertex_var.gl_Position': [0.5, 0.5, 0.0, 1.0], + 'gout.pos': [0.5, 0.5, 0.0, 1.0], + 'gout.col': [0.0, 1.0, 0.0, 1.0], + 'gout.uv': [1.0, 0.0, 0.0, 1.0], + }, + } - rdtest.log.success('Mesh data is as expected') + self.check_mesh_data(postgs_ref, postgs_data) - self.check_triangle() + rdtest.log.success('Mesh data is as expected') - rdtest.log.success('Triangle is as expected') + self.check_triangle() - pipe: rd.VKState = self.controller.GetVulkanPipelineState() + rdtest.log.success('Triangle is as expected') - if len(pipe.graphics.descriptorSets) != 1: - raise rdtest.TestFailureException("Wrong number of sets is bound: {}, not 1" - .format(len(pipe.graphics.descriptorSets))) + pipe: rd.VKState = self.controller.GetVulkanPipelineState() - desc_set: rd.VKDescriptorSet = pipe.graphics.descriptorSets[0] + if len(pipe.graphics.descriptorSets) != 1: + raise rdtest.TestFailureException("Wrong number of sets is bound: {}, not 1" + .format(len(pipe.graphics.descriptorSets))) - if len(desc_set.bindings) != 1: - raise rdtest.TestFailureException("Wrong number of bindings: {}, not 1" - .format(len(desc_set.bindings))) + desc_set: rd.VKDescriptorSet = pipe.graphics.descriptorSets[0] - binding = desc_set.bindings[0] - if binding.dynamicallyUsedCount != 1: - raise rdtest.TestFailureException("Bind doesn't have the right used count. {} is not the expected count of {}" - .format(binding.dynamicallyUsedCount, 1)) + if len(desc_set.bindings) != 1: + raise rdtest.TestFailureException("Wrong number of bindings: {}, not 1" + .format(len(desc_set.bindings))) - for idx, el in enumerate(binding.binds): - expected_used = idx == 17 - actually_used = el.dynamicallyUsed + binding = desc_set.bindings[0] + if binding.dynamicallyUsedCount != 1: + raise rdtest.TestFailureException("Bind doesn't have the right used count. {} is not the expected count of {}" + .format(binding.dynamicallyUsedCount, 1)) - if expected_used and not actually_used: - raise rdtest.TestFailureException("Bind {} element {} expected to be used, but isn't.".format(bind, idx)) + for idx, el in enumerate(binding.binds): + expected_used = idx == 17 + actually_used = el.dynamicallyUsed - if not expected_used and actually_used: - raise rdtest.TestFailureException("Bind {} element {} expected to be unused, but is.".format(bind, idx)) + if expected_used and not actually_used: + raise rdtest.TestFailureException("Bind {} element {} expected to be used, but isn't.".format(bind, idx)) - rdtest.log.success("Dynamic usage is as expected") + if not expected_used and actually_used: + raise rdtest.TestFailureException("Bind {} element {} expected to be unused, but is.".format(bind, idx)) + rdtest.log.success("Dynamic usage is as expected") + + tex = rd.TextureDisplay() + tex.overlay = rd.DebugOverlay.Drawcall + tex.resourceId = pipe.currentPass.framebuffer.attachments[0].imageResourceId + + out.SetTextureDisplay(tex) + + out.Display() + + overlay_id = out.GetDebugOverlayTexID() + + x = int(pipe.viewportScissor.viewportScissors[0].vp.width/2) + y = int(pipe.viewportScissor.viewportScissors[0].vp.height/2) + + self.check_pixel_value(overlay_id, x, y, [0.8, 0.1, 0.8, 1.0], eps=1.0 / 256.0) + self.check_pixel_value(overlay_id, x//10, y//10, [0.0, 0.0, 0.0, 0.5], eps=1.0 / 256.0) + + out.Shutdown()