Enable HLSL legalization
Also added known-good mechanism to fetch latest validated spirv-tools. Also added -Od and -Os to disable optimizer and optimize for size. Fetching spirv-tools is optional for both glsl and hlsl. Legalization of hlsl is done by default if spirv-opt is present at cmake time. Optimization for glsl is currently done through the option -Os. Legalization testing is currently only done on four existing shaders. A separate baseLegalResults directory holds those results. All previous testing is done with the optimizer disabled.
This commit is contained in:
@@ -59,9 +59,10 @@ std::string FileNameAsCustomTestSuffix(
|
||||
|
||||
using HlslCompileTest = GlslangTest<::testing::TestWithParam<FileNameEntryPointPair>>;
|
||||
using HlslCompileAndFlattenTest = GlslangTest<::testing::TestWithParam<FileNameEntryPointPair>>;
|
||||
using HlslLegalizeTest = GlslangTest<::testing::TestWithParam<FileNameEntryPointPair>>;
|
||||
|
||||
// Compiling HLSL to SPIR-V under Vulkan semantics. Expected to successfully
|
||||
// generate both AST and SPIR-V.
|
||||
// Compiling HLSL to pre-legalized SPIR-V under Vulkan semantics. Expected
|
||||
// to successfully generate both AST and SPIR-V.
|
||||
TEST_P(HlslCompileTest, FromFile)
|
||||
{
|
||||
loadFileCompileAndCheck(GlobalTestSettings.testRoot, GetParam().fileName,
|
||||
@@ -76,6 +77,16 @@ TEST_P(HlslCompileAndFlattenTest, FromFile)
|
||||
Target::BothASTAndSpv, GetParam().entryPoint);
|
||||
}
|
||||
|
||||
// Compiling HLSL to legal SPIR-V under Vulkan semantics. Expected to
|
||||
// successfully generate SPIR-V.
|
||||
TEST_P(HlslLegalizeTest, FromFile)
|
||||
{
|
||||
loadFileCompileAndCheck(GlobalTestSettings.testRoot, GetParam().fileName,
|
||||
Source::HLSL, Semantics::Vulkan,
|
||||
Target::Spv, GetParam().entryPoint,
|
||||
"/baseLegalResults/", false);
|
||||
}
|
||||
|
||||
// clang-format off
|
||||
INSTANTIATE_TEST_CASE_P(
|
||||
ToSpirv, HlslCompileTest,
|
||||
@@ -353,7 +364,20 @@ INSTANTIATE_TEST_CASE_P(
|
||||
}),
|
||||
FileNameAsCustomTestSuffix
|
||||
);
|
||||
|
||||
// clang-format on
|
||||
|
||||
// clang-format off
|
||||
INSTANTIATE_TEST_CASE_P(
|
||||
ToSpirv, HlslLegalizeTest,
|
||||
::testing::ValuesIn(std::vector<FileNameEntryPointPair>{
|
||||
{"hlsl.aliasOpaque.frag", "main"},
|
||||
{"hlsl.flattenOpaque.frag", "main"},
|
||||
{"hlsl.flattenOpaqueInit.vert", "main"},
|
||||
{"hlsl.flattenOpaqueInitMix.vert", "main"}
|
||||
}),
|
||||
FileNameAsCustomTestSuffix
|
||||
);
|
||||
// clang-format on
|
||||
|
||||
} // anonymous namespace
|
||||
} // namespace glslangtest
|
||||
|
||||
@@ -198,7 +198,8 @@ public:
|
||||
const std::string shaderName, const std::string& code,
|
||||
const std::string& entryPointName, EShMessages controls,
|
||||
bool flattenUniformArrays = false,
|
||||
EShTextureSamplerTransformMode texSampTransMode = EShTexSampTransKeep)
|
||||
EShTextureSamplerTransformMode texSampTransMode = EShTexSampTransKeep,
|
||||
bool disableOptimizer = true)
|
||||
{
|
||||
const EShLanguage kind = GetShaderStage(GetSuffix(shaderName));
|
||||
|
||||
@@ -217,8 +218,10 @@ public:
|
||||
|
||||
if (success && (controls & EShMsgSpvRules)) {
|
||||
std::vector<uint32_t> spirv_binary;
|
||||
glslang::SpvOptions options;
|
||||
options.disableOptimizer = disableOptimizer;
|
||||
glslang::GlslangToSpv(*program.getIntermediate(kind),
|
||||
spirv_binary, &logger);
|
||||
spirv_binary, &logger, &options);
|
||||
|
||||
std::ostringstream disassembly_stream;
|
||||
spv::Parameterize();
|
||||
@@ -381,18 +384,20 @@ public:
|
||||
Source source,
|
||||
Semantics semantics,
|
||||
Target target,
|
||||
const std::string& entryPointName="")
|
||||
const std::string& entryPointName="",
|
||||
const std::string& baseDir="/baseResults/",
|
||||
const bool disableOptimizer = true)
|
||||
{
|
||||
const std::string inputFname = testDir + "/" + testName;
|
||||
const std::string expectedOutputFname =
|
||||
testDir + "/baseResults/" + testName + ".out";
|
||||
testDir + baseDir + testName + ".out";
|
||||
std::string input, expectedOutput;
|
||||
|
||||
tryLoadFile(inputFname, "input", &input);
|
||||
tryLoadFile(expectedOutputFname, "expected output", &expectedOutput);
|
||||
|
||||
const EShMessages controls = DeriveOptions(source, semantics, target);
|
||||
GlslangResult result = compileAndLink(testName, input, entryPointName, controls);
|
||||
GlslangResult result = compileAndLink(testName, input, entryPointName, controls, false, EShTexSampTransKeep, disableOptimizer);
|
||||
|
||||
// Generate the hybrid output in the way of glslangValidator.
|
||||
std::ostringstream stream;
|
||||
|
||||
Reference in New Issue
Block a user