mirror of https://github.com/mosra/magnum.git
15 changed files with 443 additions and 12 deletions
@ -0,0 +1,186 @@
|
||||
#ifndef Magnum_GL_PipelineStatisticsQuery_h |
||||
#define Magnum_GL_PipelineStatisticsQuery_h |
||||
/*
|
||||
This file is part of Magnum. |
||||
|
||||
Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019 |
||||
Vladimír Vondruš <mosra@centrum.cz> |
||||
|
||||
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. |
||||
*/ |
||||
|
||||
#ifndef MAGNUM_TARGET_GLES |
||||
/** @file
|
||||
* @brief Class @ref Magnum::GL::PipelineStatisticsQuery |
||||
* @m_since_latest |
||||
*/ |
||||
#endif |
||||
|
||||
#include "Magnum/GL/AbstractQuery.h" |
||||
|
||||
#ifndef MAGNUM_TARGET_GLES |
||||
namespace Magnum { namespace GL { |
||||
|
||||
/**
|
||||
@brief Pipeline statistics query |
||||
@m_since_latest |
||||
|
||||
Provides various data about the rendering pipeline, useful for profiling and |
||||
performance measurements. |
||||
@requires_gl46 Extension @gl_extension{ARB,pipeline_statistics_query} |
||||
@requires_gl Pipeline statistics queries are not available in OpenGL ES and |
||||
WebGL. |
||||
@see @ref PrimitiveQuery, @ref SampleQuery, @ref TimeQuery |
||||
*/ |
||||
class PipelineStatisticsQuery: public AbstractQuery { |
||||
public: |
||||
/**
|
||||
* @brief Query target |
||||
* |
||||
* @m_enum_values_as_keywords |
||||
*/ |
||||
enum class Target: GLenum { |
||||
/**
|
||||
* Count of vertices submitted to the primitive assembler. Note |
||||
* that this doesn't take index buffer or strips/fans into account. |
||||
*/ |
||||
VerticesSubmitted = GL_VERTICES_SUBMITTED, |
||||
|
||||
/** Count of primitives submitted to the primitive assembler. */ |
||||
PrimitivesSubmitted = GL_PRIMITIVES_SUBMITTED, |
||||
|
||||
/**
|
||||
* Count of vertex shader invocations. For indexed draws this is |
||||
* usually less than @ref Target::VerticesSubmitted, depending on |
||||
* how well is the post-transform vertex cache used. |
||||
*/ |
||||
VertexShaderInvocations = GL_VERTEX_SHADER_INVOCATIONS, |
||||
|
||||
/**
|
||||
* Count of patches processed by tessellation control shader stage. |
||||
*/ |
||||
TessellationControlShaderPatches = GL_TESS_CONTROL_SHADER_PATCHES, |
||||
|
||||
/** Count of tessellation evaluation shader invocations. */ |
||||
TessellationEvaluationShaderInvocations = GL_TESS_EVALUATION_SHADER_INVOCATIONS, |
||||
|
||||
/** Count of geometry shader invocations. */ |
||||
GeometryShaderInvocations = GL_GEOMETRY_SHADER_INVOCATIONS, |
||||
|
||||
/**
|
||||
* Count of primitives emitted by a geometry shader. Compared to |
||||
* @ref PrimitiveQuery::Target::PrimitivesGenerated, the query |
||||
* considers all vertex streams and implementation may not count |
||||
* primitives that aren't processed further. |
||||
*/ |
||||
GeometryShaderPrimitivesEmitted = GL_GEOMETRY_SHADER_PRIMITIVES_EMITTED, |
||||
|
||||
/** Count of fragment shader invocations. */ |
||||
FragmentShaderInvocations = GL_FRAGMENT_SHADER_INVOCATIONS, |
||||
|
||||
/** Count of compute shader invocations. */ |
||||
ComputeShaderInvocations = GL_COMPUTE_SHADER_INVOCATIONS, |
||||
|
||||
/** Count of primitives that entered the clipping stage. */ |
||||
ClippingInputPrimitives = GL_CLIPPING_INPUT_PRIMITIVES, |
||||
|
||||
/**
|
||||
* Count of primitives that passed the clipping stage. In an ideal |
||||
* case of CPU-side frustum culling, the value reported by this |
||||
* query is the same as @ref Target::ClippingInputPrimitives. |
||||
*/ |
||||
ClippingOutputPrimitives = GL_CLIPPING_OUTPUT_PRIMITIVES |
||||
}; |
||||
|
||||
/**
|
||||
* @brief Wrap existing OpenGL time query object |
||||
* @param id OpenGL time query ID |
||||
* @param target Query target |
||||
* @param flags Object creation flags |
||||
* |
||||
* The @p id is expected to be of an existing OpenGL query object. |
||||
* Unlike query created using constructor, the OpenGL object is by |
||||
* default not deleted on destruction, use @p flags for different |
||||
* behavior. |
||||
* @see @ref release() |
||||
*/ |
||||
static PipelineStatisticsQuery wrap(GLuint id, Target target, ObjectFlags flags = {}) { |
||||
return PipelineStatisticsQuery{id, target, flags}; |
||||
} |
||||
|
||||
/**
|
||||
* @brief Constructor |
||||
* |
||||
* Creates new OpenGL query object. If @gl_extension{ARB,direct_state_access} |
||||
* (part of OpenGL 4.5) is not available, the query is created on first |
||||
* use. |
||||
* @see @ref PipelineStatisticsQuery(NoCreateT), @ref wrap(), @fn_gl_keyword{CreateQueries}, |
||||
* eventually @fn_gl_keyword{GenQueries} |
||||
*/ |
||||
explicit PipelineStatisticsQuery(Target target): AbstractQuery(GLenum(target)) {} |
||||
|
||||
/**
|
||||
* @brief Construct without creating the underlying OpenGL object |
||||
* |
||||
* The constructed instance is equivalent to moved-from state. Useful |
||||
* in cases where you will overwrite the instance later anyway. Move |
||||
* another object over it to make it useful. |
||||
* |
||||
* This function can be safely used for constructing (and later |
||||
* destructing) objects even without any OpenGL context being active. |
||||
* However note that this is a low-level and a potentially dangerous |
||||
* API, see the documentation of @ref NoCreate for alternatives. |
||||
* @see @ref PipelineStatisticsQuery(Target), @ref wrap() |
||||
*/ |
||||
explicit PipelineStatisticsQuery(NoCreateT) noexcept: AbstractQuery{NoCreate, GLenum(Target::VerticesSubmitted)} {} |
||||
|
||||
/** @brief Copying is not allowed */ |
||||
PipelineStatisticsQuery(const PipelineStatisticsQuery&) = delete; |
||||
|
||||
/** @brief Move constructor */ |
||||
PipelineStatisticsQuery(PipelineStatisticsQuery&&) noexcept = default; |
||||
|
||||
/** @brief Copying is not allowed */ |
||||
PipelineStatisticsQuery& operator=(const PipelineStatisticsQuery&) = delete; |
||||
|
||||
/** @brief Move assignment */ |
||||
PipelineStatisticsQuery& operator=(PipelineStatisticsQuery&&) noexcept = default; |
||||
|
||||
/* Overloads to remove WTF-factor from method chaining order */ |
||||
#if !defined(DOXYGEN_GENERATING_OUTPUT) && !defined(MAGNUM_TARGET_WEBGL) |
||||
PipelineStatisticsQuery& setLabel(const std::string& label) { |
||||
AbstractQuery::setLabel(label); |
||||
return *this; |
||||
} |
||||
template<std::size_t size> PipelineStatisticsQuery& setLabel(const char(&label)[size]) { |
||||
AbstractQuery::setLabel<size>(label); |
||||
return *this; |
||||
} |
||||
#endif |
||||
|
||||
private: |
||||
explicit PipelineStatisticsQuery(GLuint id, Target target, ObjectFlags flags) noexcept: AbstractQuery{id, GLenum(target), flags} {} |
||||
}; |
||||
|
||||
}} |
||||
#else |
||||
#error this header is not available in OpenGL ES build |
||||
#endif |
||||
|
||||
#endif |
||||
@ -0,0 +1,144 @@
|
||||
/*
|
||||
This file is part of Magnum. |
||||
|
||||
Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019 |
||||
Vladimír Vondruš <mosra@centrum.cz> |
||||
|
||||
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 <Corrade/TestSuite/Compare/Numeric.h> |
||||
|
||||
#include "Magnum/GL/AbstractShaderProgram.h" |
||||
#include "Magnum/GL/Buffer.h" |
||||
#include "Magnum/GL/Context.h" |
||||
#include "Magnum/GL/Extensions.h" |
||||
#include "Magnum/GL/Framebuffer.h" |
||||
#include "Magnum/GL/Mesh.h" |
||||
#include "Magnum/GL/OpenGLTester.h" |
||||
#include "Magnum/GL/PipelineStatisticsQuery.h" |
||||
#include "Magnum/GL/Renderbuffer.h" |
||||
#include "Magnum/GL/RenderbufferFormat.h" |
||||
#include "Magnum/GL/Shader.h" |
||||
|
||||
namespace Magnum { namespace GL { namespace Test { namespace { |
||||
|
||||
struct PipelineStatisticsQueryGLTest: OpenGLTester { |
||||
explicit PipelineStatisticsQueryGLTest(); |
||||
|
||||
void wrap(); |
||||
|
||||
void queryVerticesSubmitted(); |
||||
}; |
||||
|
||||
PipelineStatisticsQueryGLTest::PipelineStatisticsQueryGLTest() { |
||||
addTests({&PipelineStatisticsQueryGLTest::wrap, |
||||
|
||||
&PipelineStatisticsQueryGLTest::queryVerticesSubmitted}); |
||||
} |
||||
|
||||
void PipelineStatisticsQueryGLTest::wrap() { |
||||
if(!Context::current().isExtensionSupported<Extensions::ARB::pipeline_statistics_query>()) |
||||
CORRADE_SKIP(Extensions::ARB::pipeline_statistics_query::string() + std::string(" is not available")); |
||||
|
||||
GLuint id; |
||||
glGenQueries(1, &id); |
||||
|
||||
/* Releasing won't delete anything */ |
||||
{ |
||||
auto query = PipelineStatisticsQuery::wrap(id, PipelineStatisticsQuery::Target::ClippingInputPrimitives, ObjectFlag::DeleteOnDestruction); |
||||
CORRADE_COMPARE(query.release(), id); |
||||
} |
||||
|
||||
/* ...so we can wrap it again */ |
||||
PipelineStatisticsQuery::wrap(id, PipelineStatisticsQuery::Target::ClippingInputPrimitives); |
||||
glDeleteQueries(1, &id); |
||||
} |
||||
|
||||
void PipelineStatisticsQueryGLTest::queryVerticesSubmitted() { |
||||
if(!Context::current().isExtensionSupported<Extensions::ARB::pipeline_statistics_query>()) |
||||
CORRADE_SKIP(Extensions::ARB::pipeline_statistics_query::string() + std::string(" is not available")); |
||||
|
||||
/* Bind some FB to avoid errors on contexts w/o default FB */ |
||||
Renderbuffer color; |
||||
color.setStorage(RenderbufferFormat::RGBA8, Vector2i{32}); |
||||
Framebuffer fb{{{}, Vector2i{32}}}; |
||||
fb.attachRenderbuffer(Framebuffer::ColorAttachment{0}, color) |
||||
.bind(); |
||||
|
||||
struct MyShader: AbstractShaderProgram { |
||||
typedef Attribute<0, Vector2> Position; |
||||
|
||||
explicit MyShader() { |
||||
Shader vert( |
||||
#ifdef CORRADE_TARGET_APPLE |
||||
Version::GL310 |
||||
#else |
||||
Version::GL210 |
||||
#endif |
||||
, Shader::Type::Vertex); |
||||
|
||||
CORRADE_INTERNAL_ASSERT_OUTPUT(vert.addSource( |
||||
"#if __VERSION__ >= 130\n" |
||||
"#define attribute in\n" |
||||
"#endif\n" |
||||
"attribute vec4 position;\n" |
||||
"void main() {\n" |
||||
" gl_Position = position;\n" |
||||
"}\n").compile()); |
||||
|
||||
attachShader(vert); |
||||
bindAttributeLocation(Position::Location, "position"); |
||||
CORRADE_INTERNAL_ASSERT_OUTPUT(link()); |
||||
} |
||||
} shader; |
||||
|
||||
Buffer vertices; |
||||
vertices.setData({nullptr, 9*sizeof(Vector2)}, BufferUsage::StaticDraw); |
||||
|
||||
Mesh mesh; |
||||
mesh.setPrimitive(MeshPrimitive::Triangles) |
||||
.setCount(9) |
||||
.addVertexBuffer(vertices, 0, MyShader::Position()); |
||||
|
||||
MAGNUM_VERIFY_NO_GL_ERROR(); |
||||
|
||||
PipelineStatisticsQuery q{PipelineStatisticsQuery::Target::VerticesSubmitted}; |
||||
q.begin(); |
||||
|
||||
Renderer::enable(Renderer::Feature::RasterizerDiscard); |
||||
shader.draw(mesh); |
||||
|
||||
q.end(); |
||||
const bool availableBefore = q.resultAvailable(); |
||||
const UnsignedInt count = q.result<UnsignedInt>(); |
||||
const bool availableAfter = q.resultAvailable(); |
||||
|
||||
MAGNUM_VERIFY_NO_GL_ERROR(); |
||||
{ |
||||
CORRADE_EXPECT_FAIL_IF(availableBefore, "GPU faster than light?"); |
||||
CORRADE_VERIFY(!availableBefore); |
||||
} |
||||
CORRADE_VERIFY(availableAfter); |
||||
CORRADE_COMPARE(count, 9); |
||||
} |
||||
|
||||
}}}} |
||||
|
||||
CORRADE_TEST_MAIN(Magnum::GL::Test::PipelineStatisticsQueryGLTest) |
||||
@ -0,0 +1,60 @@
|
||||
/*
|
||||
This file is part of Magnum. |
||||
|
||||
Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019 |
||||
Vladimír Vondruš <mosra@centrum.cz> |
||||
|
||||
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 <Corrade/TestSuite/Tester.h> |
||||
|
||||
#include "Magnum/GL/PipelineStatisticsQuery.h" |
||||
|
||||
namespace Magnum { namespace GL { namespace Test { namespace { |
||||
|
||||
struct PipelineStatisticsQueryTest: TestSuite::Tester { |
||||
explicit PipelineStatisticsQueryTest(); |
||||
|
||||
void constructNoCreate(); |
||||
void constructCopy(); |
||||
}; |
||||
|
||||
PipelineStatisticsQueryTest::PipelineStatisticsQueryTest() { |
||||
addTests({&PipelineStatisticsQueryTest::constructNoCreate, |
||||
&PipelineStatisticsQueryTest::constructCopy}); |
||||
} |
||||
|
||||
void PipelineStatisticsQueryTest::constructNoCreate() { |
||||
{ |
||||
PipelineStatisticsQuery query{NoCreate}; |
||||
CORRADE_COMPARE(query.id(), 0); |
||||
} |
||||
|
||||
CORRADE_VERIFY(true); |
||||
} |
||||
|
||||
void PipelineStatisticsQueryTest::constructCopy() { |
||||
CORRADE_VERIFY(!(std::is_constructible<PipelineStatisticsQuery, const PipelineStatisticsQuery&>{})); |
||||
CORRADE_VERIFY(!(std::is_assignable<PipelineStatisticsQuery, const PipelineStatisticsQuery&>{})); |
||||
} |
||||
|
||||
}}}} |
||||
|
||||
CORRADE_TEST_MAIN(Magnum::GL::Test::PipelineStatisticsQueryTest) |
||||
Loading…
Reference in new issue