diff --git a/util/test/demos/CMakeLists.txt b/util/test/demos/CMakeLists.txt
index 901c5961a..1b4f24fa2 100644
--- a/util/test/demos/CMakeLists.txt
+++ b/util/test/demos/CMakeLists.txt
@@ -91,6 +91,7 @@ set(VULKAN_SRC
vk/vk_buffer_truncation.cpp
vk/vk_cbuffer_zoo.cpp
vk/vk_compute_only.cpp
+ vk/vk_counters.cpp
vk/vk_custom_border_color.cpp
vk/vk_dedicated_allocation.cpp
vk/vk_descriptor_index.cpp
diff --git a/util/test/demos/demos.vcxproj b/util/test/demos/demos.vcxproj
index 7cb494289..8ab842f39 100644
--- a/util/test/demos/demos.vcxproj
+++ b/util/test/demos/demos.vcxproj
@@ -298,6 +298,7 @@
+
diff --git a/util/test/demos/demos.vcxproj.filters b/util/test/demos/demos.vcxproj.filters
index 84f4636bd..8bc0b96dd 100644
--- a/util/test/demos/demos.vcxproj.filters
+++ b/util/test/demos/demos.vcxproj.filters
@@ -676,6 +676,9 @@
Vulkan\demos
+
+ Vulkan\demos
+
diff --git a/util/test/demos/vk/vk_counters.cpp b/util/test/demos/vk/vk_counters.cpp
new file mode 100644
index 000000000..32a6c6138
--- /dev/null
+++ b/util/test/demos/vk/vk_counters.cpp
@@ -0,0 +1,138 @@
+/******************************************************************************
+ * The MIT License (MIT)
+ *
+ * Copyright (c) 2019-2023 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_Counters, VulkanGraphicsTest)
+{
+ static constexpr const char *Description =
+ "Draws a triangle, but with a complex enough shader that it takes enough GPU time to render "
+ "to measure.";
+
+ 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}));
+
+ AllocatedImage offimgMS(
+ this,
+ vkh::ImageCreateInfo(4, 4, 0, VK_FORMAT_R16G16B16A16_SFLOAT,
+ VK_IMAGE_USAGE_TRANSFER_DST_BIT, 1, 1, VK_SAMPLE_COUNT_4_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());
+
+ vkh::cmdPipelineBarrier(
+ cmd, {
+ vkh::ImageMemoryBarrier(0, VK_ACCESS_TRANSFER_WRITE_BIT, VK_IMAGE_LAYOUT_UNDEFINED,
+ VK_IMAGE_LAYOUT_GENERAL, offimgMS.image),
+ });
+
+ vkCmdClearColorImage(cmd, offimgMS.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);
+ vkCmdDraw(cmd, 3, 1234, 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_Counters.py b/util/test/tests/Vulkan/VK_Counters.py
index dab0be34e..0199214d0 100644
--- a/util/test/tests/Vulkan/VK_Counters.py
+++ b/util/test/tests/Vulkan/VK_Counters.py
@@ -3,7 +3,7 @@ import rdtest
class VK_Counters(rdtest.TestCase):
- demos_test_name = 'VK_Simple_Triangle'
+ demos_test_name = 'VK_Counters'
def check_capture(self):
avail = self.controller.EnumerateCounters()
@@ -20,66 +20,70 @@ class VK_Counters(rdtest.TestCase):
descs[c] = self.controller.DescribeCounter(c)
action = self.find_action("Draw")
+ durationAction = action.next
# filter to only results from the draw
- results = [r for r in results if r.eventId == action.eventId]
+ results = [r for r in results if r.eventId == action.eventId or r.eventId == durationAction.eventId]
ps = samp = None
for r in results:
desc: rd.CounterDescription = descs[r.counter]
- if r.counter == rd.GPUCounter.EventGPUDuration:
- val = 0.0
- if desc.resultByteWidth == 8:
- val = r.value.d
- elif desc.resultByteWidth == 4:
- val = r.value.f
- # should not be smaller than 0.1 microseconds, and should not be more than 10 milliseconds
- if val < 1.0e-7 or val > 0.01:
- raise rdtest.TestFailureException("{} of draw {}s is unexpected".format(desc.name, val))
- else:
- rdtest.log.success("{} of draw {}s is expected".format(desc.name, val))
- elif (r.counter == rd.GPUCounter.IAPrimitives or r.counter == rd.GPUCounter.RasterizedPrimitives or
- r.counter == rd.GPUCounter.RasterizerInvocations):
- val = 0
- if desc.resultByteWidth == 8:
- val = r.value.u64
- elif desc.resultByteWidth == 4:
- val = r.value.u32
+ if r.eventId == durationAction.eventId:
+ if r.counter == rd.GPUCounter.EventGPUDuration:
+ val = 0.0
+ if desc.resultByteWidth == 8:
+ val = r.value.d
+ elif desc.resultByteWidth == 4:
+ val = r.value.f
- if val != 1:
- raise rdtest.TestFailureException("{} of draw {} is unexpected".format(desc.name, val))
- else:
- rdtest.log.success("{} of draw {} is expected".format(desc.name, val))
- elif r.counter == rd.GPUCounter.VSInvocations:
- val = 0
- if desc.resultByteWidth == 8:
- val = r.value.u64
- elif desc.resultByteWidth == 4:
- val = r.value.u32
+ # should not be smaller than 0.1 microseconds, and should not be more than 10 milliseconds
+ if val < 1.0e-7 or val > 0.01:
+ raise rdtest.TestFailureException("{} of draw {}s is unexpected".format(desc.name, val))
+ else:
+ rdtest.log.success("{} of draw {}s is expected".format(desc.name, val))
+ else:
+ if (r.counter == rd.GPUCounter.IAPrimitives or r.counter == rd.GPUCounter.RasterizedPrimitives or
+ r.counter == rd.GPUCounter.RasterizerInvocations):
+ val = 0
+ if desc.resultByteWidth == 8:
+ val = r.value.u64
+ elif desc.resultByteWidth == 4:
+ val = r.value.u32
- if val != 3:
- raise rdtest.TestFailureException("{} of draw {} is unexpected".format(desc.name, val))
- else:
- rdtest.log.success("{} of draw {} is expected".format(desc.name, val))
- elif r.counter == rd.GPUCounter.PSInvocations or r.counter == rd.GPUCounter.SamplesPassed:
- val = 0
- if desc.resultByteWidth == 8:
- val = r.value.u64
- elif desc.resultByteWidth == 4:
- val = r.value.u32
+ if val != 1:
+ raise rdtest.TestFailureException("{} of draw {} is unexpected".format(desc.name, val))
+ else:
+ rdtest.log.success("{} of draw {} is expected".format(desc.name, val))
+ elif r.counter == rd.GPUCounter.VSInvocations:
+ val = 0
+ if desc.resultByteWidth == 8:
+ val = r.value.u64
+ elif desc.resultByteWidth == 4:
+ val = r.value.u32
- if r.counter == rd.GPUCounter.PSInvocations:
- ps = val
- else:
- samp = val
+ if val != 3:
+ raise rdtest.TestFailureException("{} of draw {} is unexpected".format(desc.name, val))
+ else:
+ rdtest.log.success("{} of draw {} is expected".format(desc.name, val))
+ elif r.counter == rd.GPUCounter.PSInvocations or r.counter == rd.GPUCounter.SamplesPassed:
+ val = 0
+ if desc.resultByteWidth == 8:
+ val = r.value.u64
+ elif desc.resultByteWidth == 4:
+ val = r.value.u32
- # should be around 15000 pixels, but allow for slight rasterization differences
- if val < 14500 or val > 15500:
- raise rdtest.TestFailureException("{} of draw {} is unexpected".format(desc.name, val))
- else:
- rdtest.log.success("{} of draw {} is expected".format(desc.name, val))
+ if r.counter == rd.GPUCounter.PSInvocations:
+ ps = val
+ else:
+ samp = val
+
+ # should be around 15000 pixels, but allow for slight rasterization differences
+ if val < 14500 or val > 15500:
+ raise rdtest.TestFailureException("{} of draw {} is unexpected".format(desc.name, val))
+ else:
+ rdtest.log.success("{} of draw {} is expected".format(desc.name, val))
if ps is not None and samp is not None:
# allow 500 difference for overshading counting