mirror of
https://github.com/baldurk/renderdoc.git
synced 2026-05-06 01:50:38 +00:00
Add simple checks for large memory leaks
* Smaller memory leaks are harder to differentiate from noise, so we go for a large enough leak to be noticable over time (50,000 frames).
This commit is contained in:
@@ -27,6 +27,7 @@ set(VULKAN_SRC
|
||||
vk/vk_khr_buffer_address.cpp
|
||||
vk/vk_large_buffer.cpp
|
||||
vk/vk_large_descriptor_sets.cpp
|
||||
vk/vk_leak_check.cpp
|
||||
vk/vk_line_raster.cpp
|
||||
vk/vk_mesh_zoo.cpp
|
||||
vk/vk_misaligned_dirty.cpp
|
||||
@@ -72,6 +73,7 @@ set(OPENGL_SRC
|
||||
gl/gl_entry_points.cpp
|
||||
gl/gl_large_bcn_arrays.cpp
|
||||
gl/gl_large_buffer.cpp
|
||||
gl/gl_leak_check.cpp
|
||||
gl/gl_marker_test.cpp
|
||||
gl/gl_map_overrun.cpp
|
||||
gl/gl_mesh_zoo.cpp
|
||||
|
||||
@@ -0,0 +1,85 @@
|
||||
/******************************************************************************
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2019-2021 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 "d3d11_test.h"
|
||||
|
||||
RD_TEST(D3D11_Leak_Check, D3D11GraphicsTest)
|
||||
{
|
||||
static constexpr const char *Description =
|
||||
"Checks that we don't have memory leaks by exiting if memory usage gets too high, so we can "
|
||||
"wait and capture a late frame to check for leaks.";
|
||||
|
||||
int main()
|
||||
{
|
||||
// initialise, create window, create device, etc
|
||||
if(!Init())
|
||||
return 3;
|
||||
|
||||
ID3DBlobPtr vsblob = Compile(D3DDefaultVertex, "main", "vs_4_0");
|
||||
ID3DBlobPtr psblob = Compile(D3DDefaultPixel, "main", "ps_4_0");
|
||||
|
||||
CreateDefaultInputLayout(vsblob);
|
||||
|
||||
ID3D11VertexShaderPtr vs = CreateVS(vsblob);
|
||||
ID3D11PixelShaderPtr ps = CreatePS(psblob);
|
||||
|
||||
ID3D11BufferPtr vb = MakeBuffer().Vertex().Data(DefaultTri);
|
||||
|
||||
// make a simple texture so that the structured data includes texture initial states
|
||||
ID3D11Texture2DPtr fltTex = MakeTexture(DXGI_FORMAT_R32G32B32A32_FLOAT, 4, 4).RTV();
|
||||
ID3D11RenderTargetViewPtr fltRT = MakeRTV(fltTex);
|
||||
|
||||
while(Running())
|
||||
{
|
||||
// allow a generous 500MB, we're really only after catching big leaks here
|
||||
if(GetMemoryUsage() > 500 * 1000 * 1000)
|
||||
{
|
||||
TEST_ERROR("Memory usage of %llu is too high!", GetMemoryUsage());
|
||||
break;
|
||||
}
|
||||
|
||||
ClearRenderTargetView(bbRTV, {0.2f, 0.2f, 0.2f, 1.0f});
|
||||
ClearRenderTargetView(fltRT, {0.2f, 0.2f, 0.2f, 1.0f});
|
||||
|
||||
IASetVertexBuffer(vb, sizeof(DefaultA2V), 0);
|
||||
ctx->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
|
||||
ctx->IASetInputLayout(defaultLayout);
|
||||
|
||||
ctx->VSSetShader(vs, NULL, 0);
|
||||
ctx->PSSetShader(ps, NULL, 0);
|
||||
|
||||
RSSetViewport({0.0f, 0.0f, (float)screenWidth, (float)screenHeight, 0.0f, 1.0f});
|
||||
|
||||
ctx->OMSetRenderTargets(1, &bbRTV.GetInterfacePtr(), NULL);
|
||||
|
||||
ctx->Draw(3, 0);
|
||||
|
||||
Present();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
|
||||
REGISTER_TEST();
|
||||
@@ -0,0 +1,102 @@
|
||||
/******************************************************************************
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2019-2021 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 "d3d12_test.h"
|
||||
|
||||
RD_TEST(D3D12_Leak_Check, D3D12GraphicsTest)
|
||||
{
|
||||
static constexpr const char *Description =
|
||||
"Checks that we don't have memory leaks by exiting if memory usage gets too high, so we can "
|
||||
"wait and capture a late frame to check for leaks.";
|
||||
|
||||
int main()
|
||||
{
|
||||
// initialise, create window, create device, etc
|
||||
if(!Init())
|
||||
return 3;
|
||||
|
||||
ID3DBlobPtr vsblob = Compile(D3DDefaultVertex, "main", "vs_4_0");
|
||||
ID3DBlobPtr psblob = Compile(D3DDefaultPixel, "main", "ps_4_0");
|
||||
|
||||
ID3D12ResourcePtr vb = MakeBuffer().Data(DefaultTri);
|
||||
|
||||
ID3D12RootSignaturePtr sig = MakeSig({});
|
||||
|
||||
ID3D12PipelineStatePtr pso = MakePSO().RootSig(sig).InputLayout().VS(vsblob).PS(psblob);
|
||||
|
||||
ResourceBarrier(vb, D3D12_RESOURCE_STATE_COMMON, D3D12_RESOURCE_STATE_VERTEX_AND_CONSTANT_BUFFER);
|
||||
|
||||
ID3D12ResourcePtr rtvtex = MakeTexture(DXGI_FORMAT_R32G32B32A32_FLOAT, 4, 4)
|
||||
.RTV()
|
||||
.InitialState(D3D12_RESOURCE_STATE_RENDER_TARGET);
|
||||
|
||||
while(Running())
|
||||
{
|
||||
// allow a generous 500MB, we're really only after catching big leaks here
|
||||
if(GetMemoryUsage() > 500 * 1000 * 1000)
|
||||
{
|
||||
TEST_ERROR("Memory usage of %llu is too high!", GetMemoryUsage());
|
||||
break;
|
||||
}
|
||||
|
||||
ID3D12GraphicsCommandListPtr cmd = GetCommandBuffer();
|
||||
|
||||
Reset(cmd);
|
||||
|
||||
ID3D12ResourcePtr bb = StartUsingBackbuffer(cmd, D3D12_RESOURCE_STATE_RENDER_TARGET);
|
||||
|
||||
D3D12_CPU_DESCRIPTOR_HANDLE rtv =
|
||||
MakeRTV(bb).Format(DXGI_FORMAT_R8G8B8A8_UNORM_SRGB).CreateCPU(0);
|
||||
|
||||
ClearRenderTargetView(cmd, rtv, {0.2f, 0.2f, 0.2f, 1.0f});
|
||||
|
||||
ClearRenderTargetView(cmd, MakeRTV(rtvtex).CreateCPU(1), {0.2f, 0.2f, 0.2f, 1.0f});
|
||||
|
||||
cmd->IASetPrimitiveTopology(D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
|
||||
|
||||
IASetVertexBuffer(cmd, vb, sizeof(DefaultA2V), 0);
|
||||
cmd->SetPipelineState(pso);
|
||||
cmd->SetGraphicsRootSignature(sig);
|
||||
|
||||
RSSetViewport(cmd, {0.0f, 0.0f, (float)screenWidth, (float)screenHeight, 0.0f, 1.0f});
|
||||
RSSetScissorRect(cmd, {0, 0, screenWidth, screenHeight});
|
||||
|
||||
OMSetRenderTargets(cmd, {rtv}, {});
|
||||
|
||||
cmd->DrawInstanced(3, 1, 0, 0);
|
||||
|
||||
FinishUsingBackbuffer(cmd, D3D12_RESOURCE_STATE_RENDER_TARGET);
|
||||
|
||||
cmd->Close();
|
||||
|
||||
Submit({cmd});
|
||||
|
||||
Present();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
|
||||
REGISTER_TEST();
|
||||
@@ -141,6 +141,7 @@
|
||||
<ClCompile Include="d3d11\d3d11_feature_level_9.cpp" />
|
||||
<ClCompile Include="d3d11\d3d11_helpers.cpp" />
|
||||
<ClCompile Include="d3d11\d3d11_large_buffer.cpp" />
|
||||
<ClCompile Include="d3d11\d3d11_leak_check.cpp" />
|
||||
<ClCompile Include="d3d11\d3d11_many_rtvs.cpp" />
|
||||
<ClCompile Include="d3d11\d3d11_map_overrun.cpp" />
|
||||
<ClCompile Include="d3d11\d3d11_mesh_zoo.cpp" />
|
||||
@@ -183,6 +184,7 @@
|
||||
<ClCompile Include="d3d12\d3d12_existing_heap.cpp" />
|
||||
<ClCompile Include="d3d12\d3d12_helpers.cpp" />
|
||||
<ClCompile Include="d3d12\d3d12_large_buffer.cpp" />
|
||||
<ClCompile Include="d3d12\d3d12_leak_check.cpp" />
|
||||
<ClCompile Include="d3d12\d3d12_list_alloc_tests.cpp" />
|
||||
<ClCompile Include="d3d12\d3d12_list_types.cpp" />
|
||||
<ClCompile Include="d3d12\d3d12_mesh_zoo.cpp" />
|
||||
@@ -231,6 +233,7 @@
|
||||
<ClCompile Include="gl\gl_entry_points.cpp" />
|
||||
<ClCompile Include="gl\gl_large_bcn_arrays.cpp" />
|
||||
<ClCompile Include="gl\gl_large_buffer.cpp" />
|
||||
<ClCompile Include="gl\gl_leak_check.cpp" />
|
||||
<ClCompile Include="gl\gl_map_overrun.cpp" />
|
||||
<ClCompile Include="gl\gl_marker_test.cpp" />
|
||||
<ClCompile Include="gl\gl_mesh_zoo.cpp" />
|
||||
@@ -280,6 +283,7 @@
|
||||
<ClCompile Include="vk\vk_khr_buffer_address.cpp" />
|
||||
<ClCompile Include="vk\vk_large_buffer.cpp" />
|
||||
<ClCompile Include="vk\vk_large_descriptor_sets.cpp" />
|
||||
<ClCompile Include="vk\vk_leak_check.cpp" />
|
||||
<ClCompile Include="vk\vk_mesh_zoo.cpp" />
|
||||
<ClCompile Include="vk\vk_parameter_zoo.cpp" />
|
||||
<ClCompile Include="vk\vk_imageless_framebuffer.cpp" />
|
||||
|
||||
@@ -574,6 +574,18 @@
|
||||
<ClCompile Include="gl\gl_buffer_resizing.cpp">
|
||||
<Filter>OpenGL\demos</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="vk\vk_leak_check.cpp">
|
||||
<Filter>Vulkan\demos</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="gl\gl_leak_check.cpp">
|
||||
<Filter>OpenGL\demos</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="d3d12\d3d12_leak_check.cpp">
|
||||
<Filter>D3D12\demos</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="d3d11\d3d11_leak_check.cpp">
|
||||
<Filter>D3D11\demos</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Filter Include="D3D11">
|
||||
|
||||
@@ -0,0 +1,84 @@
|
||||
/******************************************************************************
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2019-2021 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 "gl_test.h"
|
||||
|
||||
RD_TEST(GL_Leak_Check, OpenGLGraphicsTest)
|
||||
{
|
||||
static constexpr const char *Description =
|
||||
"Checks that we don't have memory leaks by exiting if memory usage gets too high, so we can "
|
||||
"wait and capture a late frame to check for leaks.";
|
||||
|
||||
int main()
|
||||
{
|
||||
// initialise, create window, create context, etc
|
||||
if(!Init())
|
||||
return 3;
|
||||
|
||||
GLuint vao = MakeVAO();
|
||||
glBindVertexArray(vao);
|
||||
|
||||
GLuint vb = MakeBuffer();
|
||||
glBindBuffer(GL_ARRAY_BUFFER, vb);
|
||||
glBufferStorage(GL_ARRAY_BUFFER, sizeof(DefaultTri), DefaultTri, 0);
|
||||
|
||||
ConfigureDefaultVAO();
|
||||
|
||||
GLuint program = MakeProgram(GLDefaultVertex, GLDefaultPixel);
|
||||
|
||||
// make a simple texture so that the structured data includes texture initial states
|
||||
GLuint tex = MakeTexture();
|
||||
glBindTexture(GL_TEXTURE_2D, tex);
|
||||
glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGBA32F, 4, 4);
|
||||
|
||||
while(Running())
|
||||
{
|
||||
// allow a generous 500MB, we're really only after catching big leaks here
|
||||
if(GetMemoryUsage() > 500 * 1000 * 1000)
|
||||
{
|
||||
TEST_ERROR("Memory usage of %llu is too high!", GetMemoryUsage());
|
||||
break;
|
||||
}
|
||||
|
||||
float col[] = {0.2f, 0.2f, 0.2f, 1.0f};
|
||||
glClearBufferfv(GL_COLOR, 0, col);
|
||||
|
||||
glClearTexImage(tex, 0, GL_RGBA, GL_FLOAT, col);
|
||||
|
||||
glBindVertexArray(vao);
|
||||
|
||||
glUseProgram(program);
|
||||
|
||||
glViewport(0, 0, GLsizei(screenWidth), GLsizei(screenHeight));
|
||||
|
||||
glDrawArrays(GL_TRIANGLES, 0, 3);
|
||||
|
||||
Present();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
|
||||
REGISTER_TEST();
|
||||
@@ -69,6 +69,8 @@ struct OpenGLGraphicsTest : public GraphicsTest
|
||||
bool coreProfile = true;
|
||||
bool gles = false;
|
||||
|
||||
bool vsync = false;
|
||||
|
||||
GLuint swapBlitFBO;
|
||||
|
||||
GraphicsWindow *mainWindow = NULL;
|
||||
|
||||
@@ -147,6 +147,9 @@ bool OpenGLGraphicsTest::Init()
|
||||
return false;
|
||||
}
|
||||
|
||||
if(GLX_EXT_swap_control)
|
||||
glXSwapIntervalEXT(vsync ? 1 : 0);
|
||||
|
||||
PostInit();
|
||||
|
||||
return true;
|
||||
|
||||
@@ -123,6 +123,9 @@ bool OpenGLGraphicsTest::Init()
|
||||
return false;
|
||||
}
|
||||
|
||||
if(WGL_EXT_swap_control)
|
||||
wglSwapIntervalEXT(vsync ? 1 : 0);
|
||||
|
||||
PostInit();
|
||||
|
||||
return true;
|
||||
|
||||
@@ -23,8 +23,31 @@
|
||||
******************************************************************************/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include "test_common.h"
|
||||
|
||||
uint64_t GetMemoryUsage()
|
||||
{
|
||||
FILE *f = fopen("/proc/self/statm", "r");
|
||||
|
||||
if(f == NULL)
|
||||
{
|
||||
RDCWARN("Couldn't open /proc/self/statm");
|
||||
return 0;
|
||||
}
|
||||
|
||||
char line[512] = {};
|
||||
fgets(line, 511, f);
|
||||
|
||||
uint32_t vmPages = 0;
|
||||
int num = sscanf(line, "%u", &vmPages);
|
||||
|
||||
if(num == 1 && vmPages > 0)
|
||||
return vmPages * (uint64_t)sysconf(_SC_PAGESIZE);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
std::string GetCWD()
|
||||
{
|
||||
char cwd[MAX_PATH + 1] = {0};
|
||||
|
||||
@@ -287,6 +287,7 @@ void RegisterTest(TestMetadata test);
|
||||
|
||||
std::string GetCWD();
|
||||
std::string GetEnvVar(const char *var);
|
||||
uint64_t GetMemoryUsage();
|
||||
|
||||
#ifndef ARRAY_COUNT
|
||||
#define ARRAY_COUNT(arr) (sizeof(arr) / sizeof(arr[0]))
|
||||
|
||||
@@ -0,0 +1,125 @@
|
||||
/******************************************************************************
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2019-2021 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_Leak_Check, VulkanGraphicsTest)
|
||||
{
|
||||
static constexpr const char *Description =
|
||||
"Checks that we don't have memory leaks by exiting if memory usage gets too high, so we can "
|
||||
"wait and capture a late frame to check for leaks.";
|
||||
|
||||
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())
|
||||
{
|
||||
// allow a generous 500MB, we're really only after catching big leaks here
|
||||
if(GetMemoryUsage() > 500 * 1000 * 1000)
|
||||
{
|
||||
TEST_ERROR("Memory usage of %llu is too high!", GetMemoryUsage());
|
||||
break;
|
||||
}
|
||||
|
||||
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();
|
||||
@@ -24,6 +24,34 @@
|
||||
|
||||
#include "../test_common.h"
|
||||
|
||||
#include <Psapi.h>
|
||||
|
||||
uint64_t GetMemoryUsage()
|
||||
{
|
||||
HANDLE proc = GetCurrentProcess();
|
||||
|
||||
if(proc == NULL)
|
||||
{
|
||||
TEST_ERROR("Couldn't open process: %d", GetLastError());
|
||||
return 0;
|
||||
}
|
||||
|
||||
PROCESS_MEMORY_COUNTERS memInfo = {};
|
||||
|
||||
uint64_t ret = 0;
|
||||
|
||||
if(GetProcessMemoryInfo(proc, &memInfo, sizeof(memInfo)))
|
||||
{
|
||||
ret = memInfo.WorkingSetSize;
|
||||
}
|
||||
else
|
||||
{
|
||||
TEST_ERROR("Couldn't get process memory info: %d", GetLastError());
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
std::string GetCWD()
|
||||
{
|
||||
char cwd[MAX_PATH + 1] = {0};
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
import renderdoc as rd
|
||||
import rdtest
|
||||
|
||||
|
||||
class D3D11_Leak_Check(rdtest.TestCase):
|
||||
demos_test_name = 'D3D11_Leak_Check'
|
||||
demos_frame_cap = 50000
|
||||
demos_frame_count = 1
|
||||
|
||||
def check_capture(self):
|
||||
memory: int = rd.GetCurrentProcessMemoryUsage()
|
||||
|
||||
if memory > 500*1000*1000:
|
||||
raise rdtest.TestFailureException("Memory usage of {} is too high".format(memory))
|
||||
|
||||
rdtest.log.success("Capture {} opened with reasonable memory ({})".format(self.demos_frame_cap, memory))
|
||||
@@ -0,0 +1,16 @@
|
||||
import renderdoc as rd
|
||||
import rdtest
|
||||
|
||||
|
||||
class D3D12_Leak_Check(rdtest.TestCase):
|
||||
demos_test_name = 'D3D12_Leak_Check'
|
||||
demos_frame_cap = 50000
|
||||
demos_frame_count = 1
|
||||
|
||||
def check_capture(self):
|
||||
memory: int = rd.GetCurrentProcessMemoryUsage()
|
||||
|
||||
if memory > 500*1000*1000:
|
||||
raise rdtest.TestFailureException("Memory usage of {} is too high".format(memory))
|
||||
|
||||
rdtest.log.success("Capture {} opened with reasonable memory ({})".format(self.demos_frame_cap, memory))
|
||||
@@ -0,0 +1,16 @@
|
||||
import renderdoc as rd
|
||||
import rdtest
|
||||
|
||||
|
||||
class GL_Leak_Check(rdtest.TestCase):
|
||||
demos_test_name = 'GL_Leak_Check'
|
||||
demos_frame_cap = 50000
|
||||
demos_frame_count = 1
|
||||
|
||||
def check_capture(self):
|
||||
memory: int = rd.GetCurrentProcessMemoryUsage()
|
||||
|
||||
if memory > 500*1000*1000:
|
||||
raise rdtest.TestFailureException("Memory usage of {} is too high".format(memory))
|
||||
|
||||
rdtest.log.success("Capture {} opened with reasonable memory ({})".format(self.demos_frame_cap, memory))
|
||||
@@ -0,0 +1,16 @@
|
||||
import renderdoc as rd
|
||||
import rdtest
|
||||
|
||||
|
||||
class VK_Leak_Check(rdtest.TestCase):
|
||||
demos_test_name = 'VK_Leak_Check'
|
||||
demos_frame_cap = 50000
|
||||
demos_frame_count = 1
|
||||
|
||||
def check_capture(self):
|
||||
memory: int = rd.GetCurrentProcessMemoryUsage()
|
||||
|
||||
if memory > 500*1000*1000:
|
||||
raise rdtest.TestFailureException("Memory usage of {} is too high".format(memory))
|
||||
|
||||
rdtest.log.success("Capture {} opened with reasonable memory ({})".format(self.demos_frame_cap, memory))
|
||||
Reference in New Issue
Block a user