Add test that validation layers and extensions can be captured

This commit is contained in:
baldurk
2020-07-15 14:11:42 +01:00
parent 5c57493855
commit e1f90b4b01
7 changed files with 234 additions and 10 deletions
+2
View File
@@ -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
+1
View File
@@ -286,6 +286,7 @@
<ClCompile Include="vk\vk_texture_zoo.cpp" />
<ClCompile Include="vk\vk_triangle_fan.cpp" />
<ClCompile Include="vk\vk_buffer_truncation.cpp" />
<ClCompile Include="vk\vk_validation_use.cpp" />
<ClCompile Include="vk\vk_vertex_attr_zoo.cpp" />
<ClCompile Include="vk\vk_ext_buffer_address.cpp" />
<ClCompile Include="vk\vk_cbuffer_zoo.cpp" />
+3
View File
@@ -532,6 +532,9 @@
<ClCompile Include="gl\gl_state_trashing.cpp">
<Filter>OpenGL\demos</Filter>
</ClCompile>
<ClCompile Include="vk\vk_validation_use.cpp">
<Filter>Vulkan\demos</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<Filter Include="D3D11">
+83 -10
View File
@@ -119,6 +119,9 @@ void VulkanGraphicsTest::Prepare(int argc, char **argv)
static bool prepared = false;
std::vector<VkLayerProperties> availInstLayers;
std::vector<VkExtensionProperties> 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<VkLayerProperties> 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<VkExtensionProperties> 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<VkExtensionProperties> 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<VkExtensionProperties> 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<VkExtensionProperties> supportedExts;
CHECK_VKR(vkh::enumerateDeviceExtensionProperties(supportedExts, phys, NULL));
+1
View File
@@ -243,6 +243,7 @@ struct VulkanGraphicsTest : public GraphicsTest
// enabled instance extensions
std::vector<const char *> instExts;
std::vector<const char *> instLayers;
// required extensions before Init(), enabled extensions after Init()
std::vector<const char *> devExts;
+131
View File
@@ -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();
@@ -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)