Add a test of callstack collection

This commit is contained in:
baldurk
2020-01-13 19:04:44 +00:00
parent f4c864eb3d
commit 1758b32045
5 changed files with 193 additions and 0 deletions
+1
View File
@@ -44,6 +44,7 @@ set(OPENGL_SRC
gl/gl_test_linux.cpp
gl/gl_buffer_spam.cpp
gl/gl_buffer_updates.cpp
gl/gl_callstacks.cpp
gl/gl_cbuffer_zoo.cpp
gl/gl_depthstencil_fbo.cpp
gl/gl_entry_points.cpp
+1
View File
@@ -180,6 +180,7 @@
<ClCompile Include="3rdparty\glad\glad_wgl.c" />
<ClCompile Include="gl\gl_buffer_spam.cpp" />
<ClCompile Include="gl\gl_buffer_updates.cpp" />
<ClCompile Include="gl\gl_callstacks.cpp" />
<ClCompile Include="gl\gl_cbuffer_zoo.cpp" />
<ClCompile Include="gl\gl_depthstencil_fbo.cpp" />
<ClCompile Include="gl\gl_dx_interop.cpp" />
+3
View File
@@ -373,6 +373,9 @@
<ClCompile Include="d3d12\d3d12_shader_editing.cpp">
<Filter>D3D12\demos</Filter>
</ClCompile>
<ClCompile Include="gl\gl_callstacks.cpp">
<Filter>OpenGL\demos</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<Filter Include="D3D11">
+127
View File
@@ -0,0 +1,127 @@
/******************************************************************************
* 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 "gl_test.h"
RD_TEST(GL_Callstacks, OpenGLGraphicsTest)
{
static constexpr const char *Description =
"This test isn't strictly GL related but tests that callstacks resolve correctly.";
std::string common = R"EOSHADER(
#version 420 core
#define v2f v2f_block \
{ \
vec4 pos; \
vec4 col; \
vec4 uv; \
}
)EOSHADER";
std::string vertex = R"EOSHADER(
layout(location = 0) in vec3 Position;
layout(location = 1) in vec4 Color;
layout(location = 2) in vec2 UV;
out v2f vertOut;
void main()
{
vertOut.pos = vec4(Position.xyz, 1);
gl_Position = vertOut.pos;
vertOut.col = Color;
vertOut.uv = vec4(UV.xy, 0, 1);
}
)EOSHADER";
std::string pixel = R"EOSHADER(
in v2f vertIn;
layout(location = 0, index = 0) out vec4 Color;
void main()
{
Color = vertIn.col;
}
)EOSHADER";
void testFunction()
{
#line 7000
glDrawArrays(GL_TRIANGLES, 0, 3);
}
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);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(DefaultA2V), (void *)(0));
glVertexAttribPointer(1, 4, GL_FLOAT, GL_FALSE, sizeof(DefaultA2V), (void *)(sizeof(Vec3f)));
glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, sizeof(DefaultA2V),
(void *)(sizeof(Vec3f) + sizeof(Vec4f)));
glEnableVertexAttribArray(0);
glEnableVertexAttribArray(1);
glEnableVertexAttribArray(2);
GLuint program = MakeProgram(common + vertex, common + pixel);
while(Running())
{
float col[] = {0.4f, 0.5f, 0.6f, 1.0f};
glClearBufferfv(GL_COLOR, 0, col);
glBindVertexArray(vao);
glUseProgram(program);
glViewport(0, 0, GLsizei(screenWidth), GLsizei(screenHeight));
#line 8000
testFunction();
Present();
}
return 0;
}
};
REGISTER_TEST();
+61
View File
@@ -0,0 +1,61 @@
import renderdoc as rd
import rdtest
class GL_Callstacks(rdtest.TestCase):
demos_test_name = 'GL_Callstacks'
def get_capture_options(self):
ret = rd.CaptureOptions()
ret.captureCallstacks = True
return ret
def check_capture(self):
# Need capture access. Rather than trying to keep the original around, we just open a new one
cap = rd.OpenCaptureFile()
# Open a particular file
status = cap.OpenFile(self.capture_filename, '', None)
# Make sure the file opened successfully
if status != rd.ReplayStatus.Succeeded:
cap.Shutdown()
raise rdtest.TestFailureException("Couldn't open capture for access: {}".format(self.capture_filename, str(status)))
if not cap.HasCallstacks():
raise rdtest.TestFailureException("Capture does not report having callstacks")
if not cap.InitResolver(False, None):
raise rdtest.TestFailureException("Failed to initialise callstack resolver")
draw = self.find_draw("Draw")
event: rd.APIEvent = draw.events[-1]
expected_funcs = [
"GL_Callstacks::testFunction",
"GL_Callstacks::main",
]
expected_lines = [
7001,
8002
]
callstack = cap.GetResolve(list(event.callstack))
if len(callstack) < len(expected_funcs):
raise rdtest.TestFailureException("Resolved callstack isn't long enough ({} stack frames), expected at least {}".format(len(event.callstack), len(expected_funcs)))
for i in range(len(expected_funcs)):
stack: str = callstack[i]
if expected_funcs[i] not in stack:
raise rdtest.TestFailureException("Expected '{}' in '{}'".format(expected_funcs[i], stack))
idx = callstack[i].find("line")
if idx < 0:
raise rdtest.TestFailureException("Expected a line number in '{}'".format(stack))
if int(stack[idx+5:]) != expected_lines[i]:
raise rdtest.TestFailureException("Expected line number {} in '{}'".format(expected_lines[i], stack))
rdtest.log.success("Callstacks are as expected")