diff --git a/util/test/demos/CMakeLists.txt b/util/test/demos/CMakeLists.txt index 1f1078f36..90389cd6f 100644 --- a/util/test/demos/CMakeLists.txt +++ b/util/test/demos/CMakeLists.txt @@ -46,6 +46,7 @@ set(VULKAN_SRC vk/vk_structured_buffer_nested.cpp vk/vk_texture_zoo.cpp vk/vk_triangle_fan.cpp + vk/vk_validation_use.cpp vk/vk_vertex_attr_zoo.cpp vk/vk_video_textures.cpp vk/vk_vs_max_desc_set.cpp) @@ -82,6 +83,7 @@ set(OPENGL_SRC gl/gl_shader_editing.cpp gl/gl_simple_triangle.cpp gl/gl_spirv_shader.cpp + gl/gl_state_trashing.cpp gl/gl_texture_zoo.cpp gl/gl_unshared_context.cpp gl/gl_unsized_ms_fbo_attachment.cpp diff --git a/util/test/demos/demos.vcxproj b/util/test/demos/demos.vcxproj index dc9c704c1..dfb6a6beb 100644 --- a/util/test/demos/demos.vcxproj +++ b/util/test/demos/demos.vcxproj @@ -286,6 +286,7 @@ + diff --git a/util/test/demos/demos.vcxproj.filters b/util/test/demos/demos.vcxproj.filters index e2152fcd8..6100a9924 100644 --- a/util/test/demos/demos.vcxproj.filters +++ b/util/test/demos/demos.vcxproj.filters @@ -532,6 +532,9 @@ OpenGL\demos + + Vulkan\demos + diff --git a/util/test/demos/vk/vk_test.cpp b/util/test/demos/vk/vk_test.cpp index 0b72f3437..94fec6bc8 100644 --- a/util/test/demos/vk/vk_test.cpp +++ b/util/test/demos/vk/vk_test.cpp @@ -119,6 +119,9 @@ void VulkanGraphicsTest::Prepare(int argc, char **argv) static bool prepared = false; + std::vector availInstLayers; + std::vector availInstExts; + if(!prepared) { prepared = true; @@ -130,6 +133,7 @@ void VulkanGraphicsTest::Prepare(int argc, char **argv) if(volk && spv) { enabledInstExts = instExts; + enabledLayers = instLayers; enabledInstExts.push_back(VK_KHR_SURFACE_EXTENSION_NAME); @@ -149,14 +153,13 @@ void VulkanGraphicsTest::Prepare(int argc, char **argv) // enable debug utils when possible optInstExts.push_back(VK_EXT_DEBUG_UTILS_EXTENSION_NAME); - std::vector supportedLayers; - CHECK_VKR(vkh::enumerateInstanceLayerProperties(supportedLayers)); + CHECK_VKR(vkh::enumerateInstanceLayerProperties(availInstLayers)); if(debugDevice) { bool found = false; - for(const VkLayerProperties &layer : supportedLayers) + for(const VkLayerProperties &layer : availInstLayers) { if(!strcmp(layer.layerName, "VK_LAYER_KHRONOS_validation")) { @@ -168,7 +171,7 @@ void VulkanGraphicsTest::Prepare(int argc, char **argv) if(!found) { - for(const VkLayerProperties &layer : supportedLayers) + for(const VkLayerProperties &layer : availInstLayers) { if(!strcmp(layer.layerName, "VK_LAYER_LUNARG_standard_validation")) { @@ -180,23 +183,40 @@ void VulkanGraphicsTest::Prepare(int argc, char **argv) } } - std::vector supportedExts; - CHECK_VKR(vkh::enumerateInstanceExtensionProperties(supportedExts, NULL)); + CHECK_VKR(vkh::enumerateInstanceExtensionProperties(availInstExts, NULL)); for(const char *l : enabledLayers) { + bool supported = false; + for(const VkLayerProperties &layer : availInstLayers) + { + if(!strcmp(layer.layerName, l)) + { + supported = true; + break; + } + } + + if(!supported) + { + Avail = "Vulkan layer '"; + Avail += l; + Avail += "' is not available"; + return; + } + std::vector tmp; CHECK_VKR(vkh::enumerateInstanceExtensionProperties(tmp, l)); for(const VkExtensionProperties &t : tmp) - supportedExts.push_back(t); + availInstExts.push_back(t); } // strip any extensions that are not supported for(auto it = enabledInstExts.begin(); it != enabledInstExts.end();) { bool found = false; - for(VkExtensionProperties &ext : supportedExts) + for(VkExtensionProperties &ext : availInstExts) { if(!strcmp(ext.extensionName, *it)) { @@ -220,7 +240,7 @@ void VulkanGraphicsTest::Prepare(int argc, char **argv) for(const char *search : optInstExts) { bool found = false; - for(VkExtensionProperties &ext : supportedExts) + for(VkExtensionProperties &ext : availInstExts) { if(!strcmp(ext.extensionName, search)) { @@ -308,7 +328,6 @@ void VulkanGraphicsTest::Prepare(int argc, char **argv) instance = inst; phys = selectedPhys; - instExts = enabledInstExts; if(!volk) Avail = "volk did not initialise - vulkan library is not available"; @@ -392,6 +411,60 @@ void VulkanGraphicsTest::Prepare(int argc, char **argv) CHECK_FEATURE(variableMultisampleRate); CHECK_FEATURE(inheritedQueries); + CHECK_VKR(vkh::enumerateInstanceLayerProperties(availInstLayers)); + CHECK_VKR(vkh::enumerateInstanceExtensionProperties(availInstExts, NULL)); + + for(const char *l : instLayers) + { + bool layerSupported = false; + for(const VkLayerProperties &layer : availInstLayers) + { + if(!strcmp(layer.layerName, l)) + { + layerSupported = true; + break; + } + } + + if(!layerSupported) + { + Avail = "Vulkan layer '"; + Avail += l; + Avail += "' is not available"; + return; + } + + std::vector tmp; + CHECK_VKR(vkh::enumerateInstanceExtensionProperties(tmp, l)); + + for(const VkExtensionProperties &t : tmp) + availInstExts.push_back(t); + } + + for(const char *search : instExts) + { + bool extSupported = false; + for(const VkExtensionProperties &e : availInstExts) + { + if(!strcmp(e.extensionName, search)) + { + extSupported = true; + break; + } + } + + if(!extSupported) + { + Avail = "instance extension '"; + Avail += search; + Avail += "' is not available"; + return; + } + } + + instExts = enabledInstExts; + instLayers = enabledLayers; + std::vector supportedExts; CHECK_VKR(vkh::enumerateDeviceExtensionProperties(supportedExts, phys, NULL)); diff --git a/util/test/demos/vk/vk_test.h b/util/test/demos/vk/vk_test.h index a121681d8..2b47cb113 100644 --- a/util/test/demos/vk/vk_test.h +++ b/util/test/demos/vk/vk_test.h @@ -243,6 +243,7 @@ struct VulkanGraphicsTest : public GraphicsTest // enabled instance extensions std::vector instExts; + std::vector instLayers; // required extensions before Init(), enabled extensions after Init() std::vector devExts; diff --git a/util/test/demos/vk/vk_validation_use.cpp b/util/test/demos/vk/vk_validation_use.cpp new file mode 100644 index 000000000..ae249a888 --- /dev/null +++ b/util/test/demos/vk/vk_validation_use.cpp @@ -0,0 +1,131 @@ +/****************************************************************************** + * The MIT License (MIT) + * + * Copyright (c) 2019-2020 Baldur Karlsson + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + ******************************************************************************/ + +#include "vk_test.h" + +RD_TEST(VK_Validation_Use, VulkanGraphicsTest) +{ + static constexpr const char *Description = + "Uses the validation layers and a validation extension to ensure we can still replay it."; + + void Prepare(int argc, char **argv) + { + instLayers.push_back("VK_LAYER_KHRONOS_validation"); + instExts.push_back(VK_EXT_VALIDATION_FEATURES_EXTENSION_NAME); + + static VkValidationFeaturesEXT valFeatures = { + VK_STRUCTURE_TYPE_VALIDATION_FEATURES_EXT, + }; + + instInfoNext = &valFeatures; + + VulkanGraphicsTest::Prepare(argc, argv); + } + + int main() + { + // initialise, create window, create context, etc + if(!Init()) + return 3; + + VkPipelineLayout layout = createPipelineLayout(vkh::PipelineLayoutCreateInfo()); + + vkh::GraphicsPipelineCreateInfo pipeCreateInfo; + + pipeCreateInfo.layout = layout; + pipeCreateInfo.renderPass = mainWindow->rp; + + pipeCreateInfo.vertexInputState.vertexBindingDescriptions = {vkh::vertexBind(0, DefaultA2V)}; + pipeCreateInfo.vertexInputState.vertexAttributeDescriptions = { + vkh::vertexAttr(0, 0, DefaultA2V, pos), vkh::vertexAttr(1, 0, DefaultA2V, col), + vkh::vertexAttr(2, 0, DefaultA2V, uv), + }; + + pipeCreateInfo.stages = { + CompileShaderModule(VKDefaultVertex, ShaderLang::glsl, ShaderStage::vert, "main"), + CompileShaderModule(VKDefaultPixel, ShaderLang::glsl, ShaderStage::frag, "main"), + }; + + VkPipeline pipe = createGraphicsPipeline(pipeCreateInfo); + + AllocatedBuffer vb( + this, vkh::BufferCreateInfo(sizeof(DefaultTri), VK_BUFFER_USAGE_VERTEX_BUFFER_BIT | + VK_BUFFER_USAGE_TRANSFER_DST_BIT), + VmaAllocationCreateInfo({0, VMA_MEMORY_USAGE_CPU_TO_GPU})); + + vb.upload(DefaultTri); + + AllocatedImage offimg(this, vkh::ImageCreateInfo(4, 4, 0, VK_FORMAT_R32G32B32A32_SFLOAT, + VK_IMAGE_USAGE_TRANSFER_DST_BIT), + VmaAllocationCreateInfo({0, VMA_MEMORY_USAGE_GPU_ONLY})); + + while(Running()) + { + VkCommandBuffer cmd = GetCommandBuffer(); + + vkBeginCommandBuffer(cmd, vkh::CommandBufferBeginInfo()); + + VkImage swapimg = + StartUsingBackbuffer(cmd, VK_ACCESS_TRANSFER_WRITE_BIT, VK_IMAGE_LAYOUT_GENERAL); + + vkCmdClearColorImage(cmd, swapimg, VK_IMAGE_LAYOUT_GENERAL, + vkh::ClearColorValue(0.2f, 0.2f, 0.2f, 1.0f), 1, + vkh::ImageSubresourceRange()); + + vkh::cmdPipelineBarrier( + cmd, { + vkh::ImageMemoryBarrier(0, VK_ACCESS_TRANSFER_WRITE_BIT, VK_IMAGE_LAYOUT_UNDEFINED, + VK_IMAGE_LAYOUT_GENERAL, offimg.image), + }); + + vkCmdClearColorImage(cmd, offimg.image, VK_IMAGE_LAYOUT_GENERAL, + vkh::ClearColorValue(0.2f, 0.2f, 0.2f, 1.0f), 1, + vkh::ImageSubresourceRange()); + + vkCmdBeginRenderPass( + cmd, vkh::RenderPassBeginInfo(mainWindow->rp, mainWindow->GetFB(), mainWindow->scissor), + VK_SUBPASS_CONTENTS_INLINE); + + vkCmdBindPipeline(cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, pipe); + vkCmdSetViewport(cmd, 0, 1, &mainWindow->viewport); + vkCmdSetScissor(cmd, 0, 1, &mainWindow->scissor); + vkh::cmdBindVertexBuffers(cmd, 0, {vb.buffer}, {0}); + vkCmdDraw(cmd, 3, 1, 0, 0); + + vkCmdEndRenderPass(cmd); + + FinishUsingBackbuffer(cmd, VK_ACCESS_TRANSFER_WRITE_BIT, VK_IMAGE_LAYOUT_GENERAL); + + vkEndCommandBuffer(cmd); + + Submit(0, 1, {cmd}); + + Present(); + } + + return 0; + } +}; + +REGISTER_TEST(); diff --git a/util/test/tests/Vulkan/VK_Validation_Use.py b/util/test/tests/Vulkan/VK_Validation_Use.py new file mode 100644 index 000000000..6e0db0d7a --- /dev/null +++ b/util/test/tests/Vulkan/VK_Validation_Use.py @@ -0,0 +1,13 @@ +import renderdoc as rd +import rdtest + + +class VK_Validation_Use(rdtest.TestCase): + demos_test_name = 'VK_Validation_Use' + + def check_capture(self): + last_draw: rd.DrawcallDescription = self.get_last_draw() + + self.controller.SetFrameEvent(last_draw.eventId, True) + + self.check_triangle(out=last_draw.copyDestination)