Browse Source

ShaderTools: move the Stage enum to a dedicated header.

Will be used by SPIR-V reflection APIs, which don't need the whole
converter interface and all the pluginmanager stuff dragged along.
pull/495/head
Vladimír Vondruš 5 years ago
parent
commit
97d1c17ae1
  1. 1
      doc/snippets/MagnumShaderTools.cpp
  2. 28
      src/Magnum/ShaderTools/AbstractConverter.cpp
  3. 56
      src/Magnum/ShaderTools/AbstractConverter.h
  4. 4
      src/Magnum/ShaderTools/CMakeLists.txt
  5. 3
      src/Magnum/ShaderTools/ShaderTools.h
  6. 60
      src/Magnum/ShaderTools/Stage.cpp
  7. 89
      src/Magnum/ShaderTools/Stage.h
  8. 12
      src/Magnum/ShaderTools/Test/AbstractConverterTest.cpp
  9. 3
      src/Magnum/ShaderTools/Test/CMakeLists.txt
  10. 53
      src/Magnum/ShaderTools/Test/StageTest.cpp
  11. 1
      src/Magnum/ShaderTools/shaderconverter.cpp
  12. 1
      src/MagnumPlugins/AnyShaderConverter/Test/AnyConverterTest.cpp

1
doc/snippets/MagnumShaderTools.cpp

@ -31,6 +31,7 @@
#include "Magnum/FileCallback.h" #include "Magnum/FileCallback.h"
#include "Magnum/ShaderTools/AbstractConverter.h" #include "Magnum/ShaderTools/AbstractConverter.h"
#include "Magnum/ShaderTools/Stage.h"
#define DOXYGEN_IGNORE(...) __VA_ARGS__ #define DOXYGEN_IGNORE(...) __VA_ARGS__

28
src/Magnum/ShaderTools/AbstractConverter.cpp

@ -741,32 +741,4 @@ Debug& operator<<(Debug& debug, const Format value) {
return debug << "(" << Debug::nospace << reinterpret_cast<void*>(UnsignedByte(value)) << Debug::nospace << ")"; return debug << "(" << Debug::nospace << reinterpret_cast<void*>(UnsignedByte(value)) << Debug::nospace << ")";
} }
Debug& operator<<(Debug& debug, const Stage value) {
debug << "ShaderTools::Stage" << Debug::nospace;
switch(value) {
/* LCOV_EXCL_START */
#define _c(v) case Stage::v: return debug << "::" #v;
_c(Unspecified)
_c(Vertex)
_c(Fragment)
_c(Geometry)
_c(TessellationControl)
_c(TessellationEvaluation)
_c(Compute)
_c(RayGeneration)
_c(RayAnyHit)
_c(RayClosestHit)
_c(RayMiss)
_c(RayIntersection)
_c(RayCallable)
_c(MeshTask)
_c(Mesh)
#undef _c
/* LCOV_EXCL_STOP */
}
return debug << "(" << Debug::nospace << reinterpret_cast<void*>(UnsignedByte(value)) << Debug::nospace << ")";
}
}} }}

56
src/Magnum/ShaderTools/AbstractConverter.h

@ -26,7 +26,7 @@
*/ */
/** @file /** @file
* @brief Class @ref Magnum::ShaderTools::AbstractConverter, enum @ref Magnum::ShaderTools::ConverterFeature, @ref Magnum::ShaderTools::ConverterFlag, @ref Magnum::ShaderTools::Format, @ref Magnum::ShaderTools::Stage, enum set @ref Magnum::ShaderTools::ConverterFeatures, @ref Magnum::ShaderTools::ConverterFlags * @brief Class @ref Magnum::ShaderTools::AbstractConverter, enum @ref Magnum::ShaderTools::ConverterFeature, @ref Magnum::ShaderTools::ConverterFlag, @ref Magnum::ShaderTools::Format, enum set @ref Magnum::ShaderTools::ConverterFeatures, @ref Magnum::ShaderTools::ConverterFlags
* @m_since_latest * @m_since_latest
*/ */
@ -34,8 +34,13 @@
#include <Corrade/PluginManager/AbstractManagingPlugin.h> #include <Corrade/PluginManager/AbstractManagingPlugin.h>
#include "Magnum/Magnum.h" #include "Magnum/Magnum.h"
#include "Magnum/ShaderTools/ShaderTools.h"
#include "Magnum/ShaderTools/visibility.h" #include "Magnum/ShaderTools/visibility.h"
#ifdef MAGNUM_BUILD_DEPRECATED
#include "Magnum/ShaderTools/Stage.h"
#endif
namespace Magnum { namespace ShaderTools { namespace Magnum { namespace ShaderTools {
/** /**
@ -264,55 +269,6 @@ enum class Format: UnsignedInt {
*/ */
MAGNUM_SHADERTOOLS_EXPORT Debug& operator<<(Debug& debug, Format value); MAGNUM_SHADERTOOLS_EXPORT Debug& operator<<(Debug& debug, Format value);
/**
@brief Shader stage
@m_since_latest
@see @ref AbstractConverter
*/
enum class Stage: UnsignedInt {
/**
* Unspecified stage. When used in the
* @ref AbstractConverter::validateFile(),
* @ref AbstractConverter::convertFileToFile() "convertFileToFile()",
* @ref AbstractConverter::convertFileToData() "convertFileToData()",
* @ref AbstractConverter::linkFilesToFile() "linkFilesToFile()" or
* @ref AbstractConverter::linkFilesToData() "linkFilesToData()" APIs,
* particular plugins may attempt to detect the stage from filename, the
* shader stage might also be encoded directly in certain
* @ref Format "Format"s. Leaving the stage unspecified might limit
* validation and conversion capabilities, see documentation of a
* particular converter for concrete behavior.
*
* This value is guaranteed to be @cpp 0 @ce, which means you're encouraged
* to simply use @cpp {} @ce in function calls and elsewhere.
*/
Unspecified = 0,
Vertex, /**< Vertex stage */
Fragment, /**< Fragment stage */
Geometry, /**< Geometry stage */
TessellationControl, /**< Tessellation control stage */
TessellationEvaluation, /**< Tessellation evaluation stage */
Compute, /**< Compute stage */
RayGeneration, /**< Ray generation stage */
RayAnyHit, /**< Ray any hit stage */
RayClosestHit, /**< Ray closest hit stage */
RayMiss, /**< Ray miss stage */
RayIntersection, /**< Ray intersection stage */
RayCallable, /**< Ray callable stage */
MeshTask, /**< Mesh task stage */
Mesh /**< Mesh stage */
};
/**
@debugoperatorenum{Stage}
@m_since_latest
*/
MAGNUM_SHADERTOOLS_EXPORT Debug& operator<<(Debug& debug, Stage value);
/** /**
@brief Base for shader converter plugins @brief Base for shader converter plugins
@m_since_latest @m_since_latest

4
src/Magnum/ShaderTools/CMakeLists.txt

@ -30,11 +30,13 @@ set(MagnumShaderTools_SRCS )
# Files compiled with different flags for main library and unit test library # Files compiled with different flags for main library and unit test library
set(MagnumShaderTools_GracefulAssert_SRCS set(MagnumShaderTools_GracefulAssert_SRCS
AbstractConverter.cpp) AbstractConverter.cpp
Stage.cpp)
set(MagnumShaderTools_HEADERS set(MagnumShaderTools_HEADERS
AbstractConverter.h AbstractConverter.h
ShaderTools.h ShaderTools.h
Stage.h
visibility.h) visibility.h)

3
src/Magnum/ShaderTools/ShaderTools.h

@ -29,11 +29,14 @@
* @brief Forward declarations for the @ref Magnum::ShaderTools namespace * @brief Forward declarations for the @ref Magnum::ShaderTools namespace
*/ */
#include "Magnum/Types.h"
namespace Magnum { namespace ShaderTools { namespace Magnum { namespace ShaderTools {
#ifndef DOXYGEN_GENERATING_OUTPUT #ifndef DOXYGEN_GENERATING_OUTPUT
class AbstractConverter; class AbstractConverter;
#endif #endif
enum class Stage: UnsignedInt;
}} }}

60
src/Magnum/ShaderTools/Stage.cpp

@ -0,0 +1,60 @@
/*
This file is part of Magnum.
Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019,
2020, 2021 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 "Stage.h"
#include <Corrade/Utility/Debug.h>
namespace Magnum { namespace ShaderTools {
Debug& operator<<(Debug& debug, const Stage value) {
debug << "ShaderTools::Stage" << Debug::nospace;
switch(value) {
/* LCOV_EXCL_START */
#define _c(v) case Stage::v: return debug << "::" #v;
_c(Unspecified)
_c(Vertex)
_c(Fragment)
_c(Geometry)
_c(TessellationControl)
_c(TessellationEvaluation)
_c(Compute)
_c(RayGeneration)
_c(RayAnyHit)
_c(RayClosestHit)
_c(RayMiss)
_c(RayIntersection)
_c(RayCallable)
_c(MeshTask)
_c(Mesh)
#undef _c
/* LCOV_EXCL_STOP */
}
return debug << "(" << Debug::nospace << reinterpret_cast<void*>(UnsignedByte(value)) << Debug::nospace << ")";
}
}}

89
src/Magnum/ShaderTools/Stage.h

@ -0,0 +1,89 @@
#ifndef Magnum_ShaderTools_Stage_h
#define Magnum_ShaderTools_Stage_h
/*
This file is part of Magnum.
Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019,
2020, 2021 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.
*/
/** @file
* @brief Enum @ref Magnum::ShaderTools::Stage
* @m_since_latest
*/
#include "Magnum/Magnum.h"
#include "Magnum/ShaderTools/visibility.h"
namespace Magnum { namespace ShaderTools {
/**
@brief Shader stage
@m_since_latest
@see @ref AbstractConverter
*/
enum class Stage: UnsignedInt {
/**
* Unspecified stage. When used in the
* @ref AbstractConverter::validateFile(),
* @ref AbstractConverter::convertFileToFile() "convertFileToFile()",
* @ref AbstractConverter::convertFileToData() "convertFileToData()",
* @ref AbstractConverter::linkFilesToFile() "linkFilesToFile()" or
* @ref AbstractConverter::linkFilesToData() "linkFilesToData()" APIs,
* particular plugins may attempt to detect the stage from filename, the
* shader stage might also be encoded directly in certain
* @ref Format "Format"s. Leaving the stage unspecified might limit
* validation and conversion capabilities, see documentation of a
* particular converter for concrete behavior.
*
* This value is guaranteed to be @cpp 0 @ce, which means you're encouraged
* to simply use @cpp {} @ce in function calls and elsewhere.
*/
Unspecified = 0,
Vertex, /**< Vertex stage */
Fragment, /**< Fragment stage */
Geometry, /**< Geometry stage */
TessellationControl, /**< Tessellation control stage */
TessellationEvaluation, /**< Tessellation evaluation stage */
Compute, /**< Compute stage */
RayGeneration, /**< Ray generation stage */
RayAnyHit, /**< Ray any hit stage */
RayClosestHit, /**< Ray closest hit stage */
RayMiss, /**< Ray miss stage */
RayIntersection, /**< Ray intersection stage */
RayCallable, /**< Ray callable stage */
MeshTask, /**< Mesh task stage */
Mesh /**< Mesh stage */
};
/**
@debugoperatorenum{Stage}
@m_since_latest
*/
MAGNUM_SHADERTOOLS_EXPORT Debug& operator<<(Debug& debug, Stage value);
}}
#endif

12
src/Magnum/ShaderTools/Test/AbstractConverterTest.cpp

@ -36,6 +36,7 @@
#include "Magnum/FileCallback.h" #include "Magnum/FileCallback.h"
#include "Magnum/ShaderTools/AbstractConverter.h" #include "Magnum/ShaderTools/AbstractConverter.h"
#include "Magnum/ShaderTools/Stage.h"
#include "configure.h" #include "configure.h"
@ -180,7 +181,6 @@ struct AbstractConverterTest: TestSuite::Tester {
void debugFlag(); void debugFlag();
void debugFlags(); void debugFlags();
void debugFormat(); void debugFormat();
void debugStage();
}; };
AbstractConverterTest::AbstractConverterTest() { AbstractConverterTest::AbstractConverterTest() {
@ -319,8 +319,7 @@ AbstractConverterTest::AbstractConverterTest() {
&AbstractConverterTest::debugFeatures, &AbstractConverterTest::debugFeatures,
&AbstractConverterTest::debugFlag, &AbstractConverterTest::debugFlag,
&AbstractConverterTest::debugFlags, &AbstractConverterTest::debugFlags,
&AbstractConverterTest::debugFormat, &AbstractConverterTest::debugFormat});
&AbstractConverterTest::debugStage});
/* Create testing dir */ /* Create testing dir */
Utility::Directory::mkpath(SHADERTOOLS_TEST_OUTPUT_DIR); Utility::Directory::mkpath(SHADERTOOLS_TEST_OUTPUT_DIR);
@ -3428,13 +3427,6 @@ void AbstractConverterTest::debugFormat() {
CORRADE_COMPARE(out.str(), "ShaderTools::Format::Glsl ShaderTools::Format(0xf0)\n"); CORRADE_COMPARE(out.str(), "ShaderTools::Format::Glsl ShaderTools::Format(0xf0)\n");
} }
void AbstractConverterTest::debugStage() {
std::ostringstream out;
Debug{&out} << Stage::RayMiss << Stage(0xf0);
CORRADE_COMPARE(out.str(), "ShaderTools::Stage::RayMiss ShaderTools::Stage(0xf0)\n");
}
}}}} }}}}
CORRADE_TEST_MAIN(Magnum::ShaderTools::Test::AbstractConverterTest) CORRADE_TEST_MAIN(Magnum::ShaderTools::Test::AbstractConverterTest)

3
src/Magnum/ShaderTools/Test/CMakeLists.txt

@ -37,9 +37,10 @@ configure_file(${CMAKE_CURRENT_SOURCE_DIR}/configure.h.cmake
corrade_add_test(ShaderToolsAbstractConverterTest AbstractConverterTest.cpp corrade_add_test(ShaderToolsAbstractConverterTest AbstractConverterTest.cpp
LIBRARIES MagnumShaderToolsTestLib LIBRARIES MagnumShaderToolsTestLib
FILES file.dat another.dat) FILES file.dat another.dat)
target_include_directories(ShaderToolsAbstractConverterTest PRIVATE ${CMAKE_CURRENT_BINARY_DIR}) target_include_directories(ShaderToolsAbstractConverterTest PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
corrade_add_test(ShaderToolsStageTest StageTest.cpp LIBRARIES MagnumShaderTools)
set_target_properties( set_target_properties(
ShaderToolsAbstractConverterTest ShaderToolsAbstractConverterTest
ShaderToolsStageTest
PROPERTIES FOLDER "Magnum/ShaderTools/Test") PROPERTIES FOLDER "Magnum/ShaderTools/Test")

53
src/Magnum/ShaderTools/Test/StageTest.cpp

@ -0,0 +1,53 @@
/*
This file is part of Magnum.
Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019,
2020, 2021 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 <sstream>
#include <Corrade/TestSuite/Tester.h>
#include <Corrade/Utility/DebugStl.h>
#include "Magnum/ShaderTools/Stage.h"
namespace Magnum { namespace ShaderTools { namespace Test { namespace {
struct StageTest: TestSuite::Tester {
explicit StageTest();
void debug();
};
StageTest::StageTest() {
addTests({&StageTest::debug});
}
void StageTest::debug() {
std::ostringstream out;
Debug{&out} << Stage::RayMiss << Stage(0xf0);
CORRADE_COMPARE(out.str(), "ShaderTools::Stage::RayMiss ShaderTools::Stage(0xf0)\n");
}
}}}}
CORRADE_TEST_MAIN(Magnum::ShaderTools::Test::StageTest)

1
src/Magnum/ShaderTools/shaderconverter.cpp

@ -33,6 +33,7 @@
#include "Magnum/Implementation/converterUtilities.h" #include "Magnum/Implementation/converterUtilities.h"
#include "Magnum/Math/Functions.h" #include "Magnum/Math/Functions.h"
#include "Magnum/ShaderTools/AbstractConverter.h" #include "Magnum/ShaderTools/AbstractConverter.h"
#include "Magnum/ShaderTools/Stage.h"
namespace Magnum { namespace Magnum {

1
src/MagnumPlugins/AnyShaderConverter/Test/AnyConverterTest.cpp

@ -34,6 +34,7 @@
#include <Corrade/Utility/FormatStl.h> #include <Corrade/Utility/FormatStl.h>
#include "Magnum/ShaderTools/AbstractConverter.h" #include "Magnum/ShaderTools/AbstractConverter.h"
#include "Magnum/ShaderTools/Stage.h"
#include "configure.h" #include "configure.h"

Loading…
Cancel
Save