Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ESSL unit tests #1781

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion resources/Materials/TestSuite/_options.mtlx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

<!-- Comma separated list of target" specifiers to indicate which
code generators to use. -->
<input name="targets" type="string" value="genglsl,genosl,genmdl,genmsl" />
<input name="targets" type="string" value="genglsl,genosl,genmdl,genessl,genmsl" />

<!-- Check the count of number of implementations used for a given generator -->
<input name="checkImplCount" type="boolean" value="true" />
Expand Down
83 changes: 43 additions & 40 deletions source/MaterialXTest/MaterialXGenGlsl/GenGlsl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,11 @@
//

#include <MaterialXTest/External/Catch/catch.hpp>
#include <MaterialXTest/MaterialXGenShader/GenShaderUtil.h>
#include <MaterialXTest/MaterialXGenGlsl/GenGlsl.h>

#include <MaterialXCore/Document.h>

#include <MaterialXFormat/File.h>

#include <MaterialXGenShader/TypeDesc.h>
#include <MaterialXTest/MaterialXGenGlsl/GenGlsl.h>

#include <MaterialXGenGlsl/EsslShaderGenerator.h>
#include <MaterialXGenGlsl/EsslSyntax.h>
#include <MaterialXGenGlsl/GlslShaderGenerator.h>
#include <MaterialXGenGlsl/GlslSyntax.h>
#include <MaterialXGenGlsl/GlslResourceBindingContext.h>
Expand Down Expand Up @@ -95,7 +91,7 @@ TEST_CASE("GenShader: GLSL Unique Names", "[genglsl]")
GenShaderUtil::testUniqueNames(context, mx::Stage::PIXEL);
}

TEST_CASE("GenShader: Bind Light Shaders", "[genglsl]")
TEST_CASE("GenShader: GLSL Light Shaders", "[genglsl]")
{
mx::DocumentPtr doc = mx::createDocument();

Expand All @@ -120,7 +116,7 @@ TEST_CASE("GenShader: Bind Light Shaders", "[genglsl]")
}

#ifdef MATERIALX_BUILD_BENCHMARK_TESTS
TEST_CASE("GenShader: Performance Test", "[genglsl]")
TEST_CASE("GenShader: GLSL Performance Test", "[genglsl]")
{
mx::GenContext context(mx::GlslShaderGenerator::create());
BENCHMARK("Load documents, validate and generate shader")
Expand All @@ -132,43 +128,48 @@ TEST_CASE("GenShader: Performance Test", "[genglsl]")

enum class GlslType
{
Glsl400,
Glsl420,
Essl,
Glsl,
GlslLayout,
GlslVulkan
};

const std::string GlslTypeToString(GlslType e) throw()
{
switch (e)
{
case GlslType::Glsl420:
return "glsl420_layout";
case GlslType::GlslVulkan:
return "glsl420_vulkan";
case GlslType::Glsl400:
default:
return "glsl400";
}
}

static void generateGlslCode(GlslType type = GlslType::Glsl400)
static void generateGlslCode(GlslType type)
{
mx::FileSearchPath searchPath = mx::getDefaultDataSearchPath();

mx::FilePathVec testRootPaths;
testRootPaths.push_back(searchPath.find("resources/Materials/TestSuite"));
testRootPaths.push_back(searchPath.find("resources/Materials/Examples/StandardSurface"));

const mx::FilePath logPath("genglsl_" + GlslTypeToString(type) + "_generate_test.txt");
// Create the requested shader generator.
mx::ShaderGeneratorPtr generator;
if (type == GlslType::Essl)
{
generator = mx::EsslShaderGenerator::create();
}
else if (type == GlslType::GlslVulkan)
{
generator = mx::VkShaderGenerator::create();
}
else
{
generator = mx::GlslShaderGenerator::create();
}

bool writeShadersToDisk = false;
GlslShaderGeneratorTester tester((type == GlslType::GlslVulkan) ? mx::VkShaderGenerator::create() : mx::GlslShaderGenerator::create(),
testRootPaths, searchPath, logPath, writeShadersToDisk);
const std::unordered_map<GlslType, std::string> TYPE_NAME_MAP =
{
{ GlslType::Essl, "essl" },
{ GlslType::Glsl, "glsl" },
{ GlslType::GlslLayout, "glsl_layout" },
{ GlslType::GlslVulkan, "glsl_vulkan" }
};
const mx::FilePath logPath("genglsl_" + TYPE_NAME_MAP.at(type) + "_generate_test.txt");
GlslShaderGeneratorTester tester(generator, testRootPaths, searchPath, logPath, false);

// Add resource binding context for glsl 4.20
if (type == GlslType::Glsl420)
// Handle resource binding layouts if requested.
if (type == GlslType::GlslLayout)
{
// Set binding context to handle resource binding layouts
mx::GlslResourceBindingContextPtr glslresourceBinding(mx::GlslResourceBindingContext::create());
glslresourceBinding->enableSeparateBindingLocations(true);
tester.addUserData(mx::HW::USER_DATA_BINDING_CONTEXT, glslresourceBinding);
Expand All @@ -179,20 +180,22 @@ static void generateGlslCode(GlslType type = GlslType::Glsl400)
tester.validate(genOptions, optionsFilePath);
}

TEST_CASE("GenShader: ESSL Shader Generation", "[genglsl]")
{
generateGlslCode(GlslType::Essl);
}

TEST_CASE("GenShader: GLSL Shader Generation", "[genglsl]")
{
// Generate with standard GLSL i.e version 400
generateGlslCode(GlslType::Glsl400);
generateGlslCode(GlslType::Glsl);
}

TEST_CASE("GenShader: GLSL Shader with Layout Generation", "[genglsl]")
TEST_CASE("GenShader: GLSL Shader Generation with Layout", "[genglsl]")
{
// Generate GLSL with layout i.e version 400 + layout extension
generateGlslCode(GlslType::Glsl420);
generateGlslCode(GlslType::GlslLayout);
}

TEST_CASE("GenShader: Vulkan GLSL Shader", "[genglsl]")
TEST_CASE("GenShader: Vulkan GLSL Shader Generation", "[genglsl]")
{
// Generate with GLSL for Vulkan i.e. version 450
generateGlslCode(GlslType::GlslVulkan);
}