Add dedicated test for VK_Counters so GPU duration isn't degenerate

* Some cards run it so fast that the triangle takes "0" microseconds
This commit is contained in:
baldurk
2023-09-07 12:30:44 +01:00
parent 832bb4fb74
commit 1bfe6d1492
5 changed files with 196 additions and 49 deletions
+1
View File
@@ -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
+1
View File
@@ -298,6 +298,7 @@
<ClCompile Include="texture_zoo.cpp" />
<ClCompile Include="vk\vk_blend.cpp" />
<ClCompile Include="vk\vk_compute_only.cpp" />
<ClCompile Include="vk\vk_counters.cpp" />
<ClCompile Include="vk\vk_custom_border_color.cpp" />
<ClCompile Include="vk\vk_dedicated_allocation.cpp" />
<ClCompile Include="vk\vk_descriptor_reuse.cpp" />
+3
View File
@@ -676,6 +676,9 @@
<ClCompile Include="vk\vk_blend.cpp">
<Filter>Vulkan\demos</Filter>
</ClCompile>
<ClCompile Include="vk\vk_counters.cpp">
<Filter>Vulkan\demos</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<Filter Include="D3D11">
+138
View File
@@ -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();
+53 -49
View File
@@ -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