Skip to content

Commit

Permalink
Change static methods to free functions and factor out common code.
Browse files Browse the repository at this point in the history
  • Loading branch information
antiagainst committed Mar 8, 2016
1 parent 20b594d commit 081f82d
Show file tree
Hide file tree
Showing 3 changed files with 220 additions and 220 deletions.
212 changes: 106 additions & 106 deletions gtests/Spv.FromFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,112 +65,112 @@ TEST_P(CompileToSpirvTest, FromFile) {
INSTANTIATE_TEST_CASE_P(
Glsl, CompileToSpirvTest,
::testing::ValuesIn(std::vector<std::string>({
// Test looping constructs.
// No tests yet for making sure break and continue from a nested loop
// goes to the innermost target.
"spv.do-simple.vert",
"spv.do-while-continue-break.vert",
"spv.for-complex-condition.vert",
"spv.for-continue-break.vert",
"spv.for-simple.vert",
"spv.for-notest.vert",
"spv.for-nobody.vert",
"spv.while-continue-break.vert",
"spv.while-simple.vert",
// vulkan-specific tests
"spv.set.vert",
"spv.double.comp",
"spv.100ops.frag",
"spv.130.frag",
"spv.140.frag",
"spv.150.geom",
"spv.150.vert",
"spv.300BuiltIns.vert",
"spv.300layout.frag",
"spv.300layout.vert",
"spv.300layoutp.vert",
"spv.310.comp",
"spv.330.geom",
"spv.400.frag",
"spv.400.tesc",
"spv.400.tese",
"spv.420.geom",
"spv.430.vert",
"spv.accessChain.frag",
"spv.aggOps.frag",
"spv.always-discard.frag",
"spv.always-discard2.frag",
"spv.bitCast.frag",
"spv.bool.vert",
"spv.boolInBlock.frag",
"spv.branch-return.vert",
"spv.conditionalDiscard.frag",
"spv.conversion.frag",
"spv.dataOut.frag",
"spv.dataOutIndirect.frag",
"spv.dataOutIndirect.vert",
"spv.deepRvalue.frag",
"spv.depthOut.frag",
"spv.discard-dce.frag",
"spv.doWhileLoop.frag",
"spv.earlyReturnDiscard.frag",
"spv.flowControl.frag",
"spv.forLoop.frag",
"spv.forwardFun.frag",
"spv.functionCall.frag",
"spv.functionSemantics.frag",
"spv.interpOps.frag",
"spv.layoutNested.vert",
"spv.length.frag",
"spv.localAggregates.frag",
"spv.loops.frag",
"spv.loopsArtificial.frag",
"spv.matFun.vert",
"spv.matrix.frag",
"spv.matrix2.frag",
"spv.merge-unreachable.frag",
"spv.newTexture.frag",
"spv.nonSquare.vert",
"spv.Operations.frag",
"spv.intOps.vert",
"spv.precision.frag",
"spv.prepost.frag",
"spv.qualifiers.vert",
"spv.shiftOps.frag",
"spv.simpleFunctionCall.frag",
"spv.simpleMat.vert",
"spv.sparseTexture.frag",
"spv.sparseTextureClamp.frag",
"spv.structAssignment.frag",
"spv.structDeref.frag",
"spv.structure.frag",
"spv.switch.frag",
"spv.swizzle.frag",
"spv.test.frag",
"spv.test.vert",
"spv.texture.frag",
"spv.texture.vert",
"spv.image.frag",
"spv.types.frag",
"spv.uint.frag",
"spv.uniformArray.frag",
"spv.variableArrayIndex.frag",
"spv.varyingArray.frag",
"spv.varyingArrayIndirect.frag",
"spv.voidFunction.frag",
"spv.whileLoop.frag",
"spv.AofA.frag",
"spv.queryL.frag",
"spv.separate.frag",
"spv.shortCircuit.frag",
"spv.pushConstant.vert",
"spv.subpass.frag",
"spv.specConstant.vert",
"spv.specConstant.comp",
// GLSL-level semantics
"vulkan.frag",
"vulkan.vert",
"vulkan.comp"
// Test looping constructs.
// No tests yet for making sure break and continue from a nested loop
// goes to the innermost target.
"spv.do-simple.vert",
"spv.do-while-continue-break.vert",
"spv.for-complex-condition.vert",
"spv.for-continue-break.vert",
"spv.for-simple.vert",
"spv.for-notest.vert",
"spv.for-nobody.vert",
"spv.while-continue-break.vert",
"spv.while-simple.vert",
// vulkan-specific tests
"spv.set.vert",
"spv.double.comp",
"spv.100ops.frag",
"spv.130.frag",
"spv.140.frag",
"spv.150.geom",
"spv.150.vert",
"spv.300BuiltIns.vert",
"spv.300layout.frag",
"spv.300layout.vert",
"spv.300layoutp.vert",
"spv.310.comp",
"spv.330.geom",
"spv.400.frag",
"spv.400.tesc",
"spv.400.tese",
"spv.420.geom",
"spv.430.vert",
"spv.accessChain.frag",
"spv.aggOps.frag",
"spv.always-discard.frag",
"spv.always-discard2.frag",
"spv.bitCast.frag",
"spv.bool.vert",
"spv.boolInBlock.frag",
"spv.branch-return.vert",
"spv.conditionalDiscard.frag",
"spv.conversion.frag",
"spv.dataOut.frag",
"spv.dataOutIndirect.frag",
"spv.dataOutIndirect.vert",
"spv.deepRvalue.frag",
"spv.depthOut.frag",
"spv.discard-dce.frag",
"spv.doWhileLoop.frag",
"spv.earlyReturnDiscard.frag",
"spv.flowControl.frag",
"spv.forLoop.frag",
"spv.forwardFun.frag",
"spv.functionCall.frag",
"spv.functionSemantics.frag",
"spv.interpOps.frag",
"spv.layoutNested.vert",
"spv.length.frag",
"spv.localAggregates.frag",
"spv.loops.frag",
"spv.loopsArtificial.frag",
"spv.matFun.vert",
"spv.matrix.frag",
"spv.matrix2.frag",
"spv.merge-unreachable.frag",
"spv.newTexture.frag",
"spv.nonSquare.vert",
"spv.Operations.frag",
"spv.intOps.vert",
"spv.precision.frag",
"spv.prepost.frag",
"spv.qualifiers.vert",
"spv.shiftOps.frag",
"spv.simpleFunctionCall.frag",
"spv.simpleMat.vert",
"spv.sparseTexture.frag",
"spv.sparseTextureClamp.frag",
"spv.structAssignment.frag",
"spv.structDeref.frag",
"spv.structure.frag",
"spv.switch.frag",
"spv.swizzle.frag",
"spv.test.frag",
"spv.test.vert",
"spv.texture.frag",
"spv.texture.vert",
"spv.image.frag",
"spv.types.frag",
"spv.uint.frag",
"spv.uniformArray.frag",
"spv.variableArrayIndex.frag",
"spv.varyingArray.frag",
"spv.varyingArrayIndirect.frag",
"spv.voidFunction.frag",
"spv.whileLoop.frag",
"spv.AofA.frag",
"spv.queryL.frag",
"spv.separate.frag",
"spv.shortCircuit.frag",
"spv.pushConstant.vert",
"spv.subpass.frag",
"spv.specConstant.vert",
"spv.specConstant.comp",
// GLSL-level semantics
"vulkan.frag",
"vulkan.vert",
"vulkan.comp"
})),
FileNameAsCustomTestName
);
Expand Down
55 changes: 55 additions & 0 deletions gtests/TestFixture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,59 @@ std::string FileNameAsCustomTestName(
return name;
}

EShLanguage GetGlslLanguageForStage(const std::string& stage) {
if (stage == "vert") {
return EShLangVertex;
} else if (stage == "tesc") {
return EShLangTessControl;
} else if (stage == "tese") {
return EShLangTessEvaluation;
} else if (stage == "geom") {
return EShLangGeometry;
} else if (stage == "frag") {
return EShLangFragment;
} else if (stage == "comp") {
return EShLangCompute;
} else {
assert(0 && "Unknown shader stage");
return EShLangCount;
}
}

EShMessages GetSpirvMessageOptionsForSemantics(Semantics semantics) {
switch (semantics) {
case Semantics::OpenGL:
return EShMsgSpvRules;
case Semantics::Vulkan:
return static_cast<EShMessages>(EShMsgSpvRules | EShMsgVulkanRules);
}
}

std::pair<bool, std::string> ReadFile(const std::string& path) {
std::ifstream fstream(path, std::ios::in);
if (fstream) {
std::string contents;
fstream.seekg(0, std::ios::end);
contents.reserve(fstream.tellg());
fstream.seekg(0, std::ios::beg);
contents.assign((std::istreambuf_iterator<char>(fstream)),
std::istreambuf_iterator<char>());
return std::make_pair(true, contents);
}
return std::make_pair(false, "");
}

bool WriteFile(const std::string& path, const std::string& contents) {
std::ofstream fstream(path, std::ios::out);
if (!fstream) return false;
fstream << contents;
fstream.flush();
return true;
}

std::string GetSuffix(const std::string& name) {
const size_t pos = name.rfind('.');
return (pos == std::string::npos) ? "" : name.substr(name.rfind('.') + 1);
}

} // namespace glslangtest
Loading

0 comments on commit 081f82d

Please sign in to comment.