From f8c5c2878b8af11d78577f20da302c5c14bffffe Mon Sep 17 00:00:00 2001 From: Aliya Pazylbekova Date: Fri, 17 Apr 2020 19:52:40 -0400 Subject: [PATCH] Vk pixel history: unbound fragment shader Add support for unbound fragment shader. --- renderdoc/driver/vulkan/vk_pixelhistory.cpp | 35 +++++++++++++++----- util/test/demos/vk/vk_pixel_history_test.cpp | 18 +++++++--- util/test/tests/Vulkan/Vk_Pixel_History.py | 3 ++ 3 files changed, 44 insertions(+), 12 deletions(-) diff --git a/renderdoc/driver/vulkan/vk_pixelhistory.cpp b/renderdoc/driver/vulkan/vk_pixelhistory.cpp index c8578f7c3..e263bdda8 100644 --- a/renderdoc/driver/vulkan/vk_pixelhistory.cpp +++ b/renderdoc/driver/vulkan/vk_pixelhistory.cpp @@ -49,12 +49,13 @@ enum TestEnabled_FragmentDiscard = 1 << 6, Blending_Enabled = 1 << 7, - TestMustFail_Culling = 1 << 8, - TestMustFail_Scissor = 1 << 9, - TestMustPass_Scissor = 1 << 10, - TestMustFail_DepthTesting = 1 << 11, - TestMustFail_StencilTesting = 1 << 12, - TestMustFail_SampleMask = 1 << 13, + UnboundFragmentShader = 1 << 8, + TestMustFail_Culling = 1 << 9, + TestMustFail_Scissor = 1 << 10, + TestMustPass_Scissor = 1 << 11, + TestMustFail_DepthTesting = 1 << 12, + TestMustFail_StencilTesting = 1 << 13, + TestMustFail_SampleMask = 1 << 14, }; struct CopyPixelParams @@ -1480,6 +1481,9 @@ private: } } + if(p.shaders[StageIndex(VK_SHADER_STAGE_FRAGMENT_BIT)].module == ResourceId()) + flags |= UnboundFragmentShader; + // Samples { // TODO: figure out if we always need to check this. @@ -2139,14 +2143,27 @@ struct VulkanPixelHistoryPerFragmentCallback : VulkanPixelHistoryCallback } // Output the primitive ID. + VkPipelineShaderStageCreateInfo stageCI = {}; + stageCI.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; + stageCI.stage = VK_SHADER_STAGE_FRAGMENT_BIT; + stageCI.module = m_ShaderCache->GetPrimitiveIdShader(framebufferIndex); + stageCI.pName = "main"; + bool fsFound = false; for(uint32_t i = 0; i < pipeCreateInfo.stageCount; i++) { if(stages[i].stage == VK_SHADER_STAGE_FRAGMENT_BIT) { - stages[i].module = m_ShaderCache->GetPrimitiveIdShader(framebufferIndex); - stages[i].pName = "main"; + stages[i] = stageCI; + fsFound = true; + break; } } + if(!fsFound) + { + stages.push_back(stageCI); + pipeCreateInfo.stageCount = (uint32_t)stages.size(); + pipeCreateInfo.pStages = stages.data(); + } vkr = m_pDriver->vkCreateGraphicsPipelines(m_pDriver->GetDev(), VK_NULL_HANDLE, 1, &pipeCreateInfo, NULL, &pipes.primitiveIdPipe); @@ -2831,6 +2848,8 @@ rdcarray VulkanReplay::PixelHistory(rdcarray even mod.scissorClipped = true; if(flags & TestMustFail_SampleMask) mod.sampleMasked = true; + if(flags & UnboundFragmentShader) + mod.unboundPS = true; UpdateTestsFailed(tfCb, eventId, flags, mod); } diff --git a/util/test/demos/vk/vk_pixel_history_test.cpp b/util/test/demos/vk/vk_pixel_history_test.cpp index 995c71448..a34fb7ee9 100644 --- a/util/test/demos/vk/vk_pixel_history_test.cpp +++ b/util/test/demos/vk/vk_pixel_history_test.cpp @@ -221,10 +221,12 @@ void main() vkh::vertexAttr(2, 0, DefaultA2V, uv), }; - pipeCreateInfo.stages = { - CompileShaderModule(common + vertex, ShaderLang::glsl, ShaderStage::vert, "main"), - CompileShaderModule(common + pixel, ShaderLang::glsl, ShaderStage::frag, "main"), - }; + VkPipelineShaderStageCreateInfo vertexShader = + CompileShaderModule(common + vertex, ShaderLang::glsl, ShaderStage::vert, "main"); + VkPipelineShaderStageCreateInfo fragmentShader = + CompileShaderModule(common + pixel, ShaderLang::glsl, ShaderStage::frag, "main"); + + pipeCreateInfo.stages = {vertexShader, fragmentShader}; pipeCreateInfo.rasterizationState.depthClampEnable = VK_FALSE; pipeCreateInfo.rasterizationState.cullMode = VK_CULL_MODE_BACK_BIT; @@ -249,6 +251,10 @@ void main() pipeCreateInfo.depthStencilState.stencilTestEnable = VK_FALSE; VkPipeline backgroundPipe = createGraphicsPipeline(pipeCreateInfo); + pipeCreateInfo.stages = {vertexShader}; + VkPipeline noFsPipe = createGraphicsPipeline(pipeCreateInfo); + pipeCreateInfo.stages = {vertexShader, fragmentShader}; + pipeCreateInfo.depthStencilState.stencilTestEnable = VK_TRUE; pipeCreateInfo.depthStencilState.front.compareOp = VK_COMPARE_OP_GREATER; VkPipeline pipe = createGraphicsPipeline(pipeCreateInfo); @@ -319,6 +325,10 @@ void main() vkCmdBindPipeline(cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, depthWritePipe); vkCmdDraw(cmd, 3, 1, 0, 0); + setMarker(cmd, "Unbound Fragment Shader"); + vkCmdBindPipeline(cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, noFsPipe); + vkCmdDraw(cmd, 3, 1, 3, 0); + setMarker(cmd, "Stencil Write"); vkCmdBindPipeline(cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, stencilWritePipe); vkCmdDraw(cmd, 3, 1, 3, 0); diff --git a/util/test/tests/Vulkan/Vk_Pixel_History.py b/util/test/tests/Vulkan/Vk_Pixel_History.py index 8fb7105e4..dde312052 100644 --- a/util/test/tests/Vulkan/Vk_Pixel_History.py +++ b/util/test/tests/Vulkan/Vk_Pixel_History.py @@ -12,6 +12,7 @@ def shader_out_col(x): return value_selector(x.shaderOut.col) def pre_mod_col(x): return value_selector(x.preMod.col) def post_mod_col(x): return value_selector(x.postMod.col) def primitive_id(x): return x.primitiveID +def unboundPS(x): return x.unboundPS class VK_Pixel_History(rdtest.TestCase): demos_test_name = 'VK_Pixel_History_Test' @@ -47,6 +48,7 @@ class VK_Pixel_History(rdtest.TestCase): begin_renderpass_eid = self.find_draw("Begin RenderPass").next.eventId depth_write_eid = self.find_draw("Depth Write").next.eventId stencil_write_eid = self.find_draw("Stencil Write").next.eventId + unbound_fs_eid = self.find_draw("Unbound Fragment Shader").next.eventId background_eid = self.find_draw("Background").next.eventId cull_eid = self.find_draw("Cull Front").next.eventId test_eid = self.find_draw("Test").next.eventId @@ -57,6 +59,7 @@ class VK_Pixel_History(rdtest.TestCase): modifs: List[rd.PixelModification] = self.controller.PixelHistory(tex, x, y, sub, rt.typeCast) events = [ [[event_id, begin_renderpass_eid], [passed, True]], + [[event_id, unbound_fs_eid], [passed, True], [unboundPS, True], [primitive_id, 0]], [[event_id, stencil_write_eid], [passed, True]], [[event_id, background_eid], [depth_test_failed, True], [post_mod_col, (1.0, 0.0, 0.0, 1.0)]], [[event_id, test_eid], [stencil_test_failed, True]],