2016-03-05 00:22:34 +03:00
|
|
|
//
|
|
|
|
// Copyright (C) 2016 Google, Inc.
|
|
|
|
//
|
|
|
|
// All rights reserved.
|
|
|
|
//
|
|
|
|
// Redistribution and use in source and binary forms, with or without
|
|
|
|
// modification, are permitted provided that the following conditions
|
|
|
|
// are met:
|
|
|
|
//
|
|
|
|
// Redistributions of source code must retain the above copyright
|
|
|
|
// notice, this list of conditions and the following disclaimer.
|
|
|
|
//
|
|
|
|
// Redistributions in binary form must reproduce the above
|
|
|
|
// copyright notice, this list of conditions and the following
|
|
|
|
// disclaimer in the documentation and/or other materials provided
|
|
|
|
// with the distribution.
|
|
|
|
//
|
|
|
|
// Neither the name of Google Inc. nor the names of its
|
|
|
|
// contributors may be used to endorse or promote products derived
|
|
|
|
// from this software without specific prior written permission.
|
|
|
|
//
|
|
|
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
|
|
|
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
|
|
|
// COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
|
|
|
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
|
|
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
|
|
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
|
|
|
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
// POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
|
|
|
#include <algorithm>
|
|
|
|
|
|
|
|
#include <gtest/gtest.h>
|
|
|
|
|
|
|
|
#include "TestFixture.h"
|
|
|
|
|
|
|
|
namespace glslangtest {
|
|
|
|
namespace {
|
|
|
|
|
HLSL: Add location offsets per resource type
This PR adds the ability to offset sampler, texture, and UBO bindings
from provided base bindings, and to auto-number bindings that are not
provided with explicit register numbers. The mechanism works as
follows:
- Offsets may be given on the command line for all stages, or
individually for one or more single stages, in which case the
offset will be auto-selected according to the stage being
compiled. There is also an API to set them. The new command line
options are --shift-sampler-binding, --shift-texture-binding, and
--shift-UBO-binding.
- Uniforms which are not given explicit bindings in the source code
are auto-numbered if and only if they are in live code as
determined by the algorithm used to build the reflection
database, and the --auto-map-bindings option is given. This auto-numbering
avoids using any binding slots which were explicitly provided in
the code, whether or not that explicit use was live. E.g, "uniform
Texture1D foo : register(t3);" with --shift-texture-binding 10 will
reserve binding 13, whether or not foo is used in live code.
- Shorter synonyms for the command line options are available. See
the --help output.
The testing infrastructure is slightly extended to allow use of the
binding offset API, and two new tests spv.register.(no)autoassign.frag are
added for comparing the resulting SPIR-V.
2016-09-08 00:20:19 +03:00
|
|
|
struct IoMapData {
|
|
|
|
const char* fileName;
|
|
|
|
const char* entryPoint;
|
|
|
|
int baseSamplerBinding;
|
|
|
|
int baseTextureBinding;
|
|
|
|
int baseUboBinding;
|
|
|
|
bool autoMapBindings;
|
|
|
|
};
|
|
|
|
|
|
|
|
std::string FileNameAsCustomTestSuffixIoMap(
|
|
|
|
const ::testing::TestParamInfo<IoMapData>& info) {
|
|
|
|
std::string name = info.param.fileName;
|
|
|
|
// A valid test case suffix cannot have '.' and '-' inside.
|
|
|
|
std::replace(name.begin(), name.end(), '.', '_');
|
|
|
|
std::replace(name.begin(), name.end(), '-', '_');
|
|
|
|
return name;
|
|
|
|
}
|
|
|
|
|
2016-07-07 22:20:00 +03:00
|
|
|
using CompileVulkanToSpirvTest = GlslangTest<::testing::TestWithParam<std::string>>;
|
|
|
|
using CompileOpenGLToSpirvTest = GlslangTest<::testing::TestWithParam<std::string>>;
|
2016-03-05 00:22:34 +03:00
|
|
|
using VulkanSemantics = GlslangTest<::testing::TestWithParam<std::string>>;
|
2016-07-08 02:46:42 +03:00
|
|
|
using OpenGLSemantics = GlslangTest<::testing::TestWithParam<std::string>>;
|
2016-05-24 01:07:07 +03:00
|
|
|
using VulkanAstSemantics = GlslangTest<::testing::TestWithParam<std::string>>;
|
HLSL: Add location offsets per resource type
This PR adds the ability to offset sampler, texture, and UBO bindings
from provided base bindings, and to auto-number bindings that are not
provided with explicit register numbers. The mechanism works as
follows:
- Offsets may be given on the command line for all stages, or
individually for one or more single stages, in which case the
offset will be auto-selected according to the stage being
compiled. There is also an API to set them. The new command line
options are --shift-sampler-binding, --shift-texture-binding, and
--shift-UBO-binding.
- Uniforms which are not given explicit bindings in the source code
are auto-numbered if and only if they are in live code as
determined by the algorithm used to build the reflection
database, and the --auto-map-bindings option is given. This auto-numbering
avoids using any binding slots which were explicitly provided in
the code, whether or not that explicit use was live. E.g, "uniform
Texture1D foo : register(t3);" with --shift-texture-binding 10 will
reserve binding 13, whether or not foo is used in live code.
- Shorter synonyms for the command line options are available. See
the --help output.
The testing infrastructure is slightly extended to allow use of the
binding offset API, and two new tests spv.register.(no)autoassign.frag are
added for comparing the resulting SPIR-V.
2016-09-08 00:20:19 +03:00
|
|
|
using HlslSemantics = GlslangTest<::testing::TestWithParam<IoMapData>>;
|
2016-03-05 00:22:34 +03:00
|
|
|
|
|
|
|
// Compiling GLSL to SPIR-V under Vulkan semantics. Expected to successfully
|
|
|
|
// generate SPIR-V.
|
2016-07-07 22:20:00 +03:00
|
|
|
TEST_P(CompileVulkanToSpirvTest, FromFile)
|
2016-03-05 00:22:34 +03:00
|
|
|
{
|
|
|
|
loadFileCompileAndCheck(GLSLANG_TEST_DIRECTORY, GetParam(),
|
2016-05-16 19:50:30 +03:00
|
|
|
Source::GLSL, Semantics::Vulkan,
|
|
|
|
Target::Spv);
|
2016-03-05 00:22:34 +03:00
|
|
|
}
|
|
|
|
|
2016-07-07 22:20:00 +03:00
|
|
|
// Compiling GLSL to SPIR-V under OpenGL semantics. Expected to successfully
|
|
|
|
// generate SPIR-V.
|
|
|
|
TEST_P(CompileOpenGLToSpirvTest, FromFile)
|
|
|
|
{
|
|
|
|
loadFileCompileAndCheck(GLSLANG_TEST_DIRECTORY, GetParam(),
|
|
|
|
Source::GLSL, Semantics::OpenGL,
|
|
|
|
Target::Spv);
|
|
|
|
}
|
|
|
|
|
2016-03-05 00:22:34 +03:00
|
|
|
// GLSL-level Vulkan semantics test. Expected to error out before generating
|
|
|
|
// SPIR-V.
|
|
|
|
TEST_P(VulkanSemantics, FromFile)
|
|
|
|
{
|
|
|
|
loadFileCompileAndCheck(GLSLANG_TEST_DIRECTORY, GetParam(),
|
2016-05-16 19:50:30 +03:00
|
|
|
Source::GLSL, Semantics::Vulkan,
|
|
|
|
Target::Spv);
|
2016-03-05 00:22:34 +03:00
|
|
|
}
|
|
|
|
|
2016-07-08 02:46:42 +03:00
|
|
|
// GLSL-level Vulkan semantics test. Expected to error out before generating
|
|
|
|
// SPIR-V.
|
|
|
|
TEST_P(OpenGLSemantics, FromFile)
|
|
|
|
{
|
|
|
|
loadFileCompileAndCheck(GLSLANG_TEST_DIRECTORY, GetParam(),
|
|
|
|
Source::GLSL, Semantics::OpenGL,
|
|
|
|
Target::Spv);
|
|
|
|
}
|
|
|
|
|
2016-05-24 01:07:07 +03:00
|
|
|
// GLSL-level Vulkan semantics test that need to see the AST for validation.
|
|
|
|
TEST_P(VulkanAstSemantics, FromFile)
|
|
|
|
{
|
|
|
|
loadFileCompileAndCheck(GLSLANG_TEST_DIRECTORY, GetParam(),
|
|
|
|
Source::GLSL, Semantics::Vulkan,
|
|
|
|
Target::AST);
|
|
|
|
}
|
|
|
|
|
HLSL: Add location offsets per resource type
This PR adds the ability to offset sampler, texture, and UBO bindings
from provided base bindings, and to auto-number bindings that are not
provided with explicit register numbers. The mechanism works as
follows:
- Offsets may be given on the command line for all stages, or
individually for one or more single stages, in which case the
offset will be auto-selected according to the stage being
compiled. There is also an API to set them. The new command line
options are --shift-sampler-binding, --shift-texture-binding, and
--shift-UBO-binding.
- Uniforms which are not given explicit bindings in the source code
are auto-numbered if and only if they are in live code as
determined by the algorithm used to build the reflection
database, and the --auto-map-bindings option is given. This auto-numbering
avoids using any binding slots which were explicitly provided in
the code, whether or not that explicit use was live. E.g, "uniform
Texture1D foo : register(t3);" with --shift-texture-binding 10 will
reserve binding 13, whether or not foo is used in live code.
- Shorter synonyms for the command line options are available. See
the --help output.
The testing infrastructure is slightly extended to allow use of the
binding offset API, and two new tests spv.register.(no)autoassign.frag are
added for comparing the resulting SPIR-V.
2016-09-08 00:20:19 +03:00
|
|
|
// HLSL-level Vulkan semantics tests.
|
|
|
|
TEST_P(HlslSemantics, FromFile)
|
|
|
|
{
|
|
|
|
loadFileCompileIoMapAndCheck(GLSLANG_TEST_DIRECTORY, GetParam().fileName,
|
|
|
|
Source::HLSL, Semantics::Vulkan,
|
|
|
|
Target::Spv, GetParam().entryPoint,
|
|
|
|
GetParam().baseSamplerBinding,
|
|
|
|
GetParam().baseTextureBinding,
|
|
|
|
GetParam().baseUboBinding,
|
|
|
|
GetParam().autoMapBindings);
|
|
|
|
}
|
|
|
|
|
2016-03-05 00:22:34 +03:00
|
|
|
// clang-format off
|
|
|
|
INSTANTIATE_TEST_CASE_P(
|
2016-07-07 22:20:00 +03:00
|
|
|
Glsl, CompileVulkanToSpirvTest,
|
2016-03-05 00:22:34 +03:00
|
|
|
::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",
|
2016-06-15 05:38:58 +03:00
|
|
|
"spv.310.bitcast.frag",
|
2016-03-05 00:22:34 +03:00
|
|
|
"spv.330.geom",
|
|
|
|
"spv.400.frag",
|
|
|
|
"spv.400.tesc",
|
|
|
|
"spv.400.tese",
|
|
|
|
"spv.420.geom",
|
2016-07-08 23:05:15 +03:00
|
|
|
"spv.430.frag",
|
2016-03-05 00:22:34 +03:00
|
|
|
"spv.430.vert",
|
2016-07-01 06:47:35 +03:00
|
|
|
"spv.450.tesc",
|
2016-03-05 00:22:34 +03:00
|
|
|
"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",
|
2016-04-22 11:51:45 +03:00
|
|
|
"spv.int64.frag",
|
2016-03-05 00:22:34 +03:00
|
|
|
"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.memoryQualifier.frag",
|
|
|
|
"spv.merge-unreachable.frag",
|
2016-09-02 20:20:21 +03:00
|
|
|
"spv.multiStruct.comp",
|
|
|
|
"spv.multiStructFuncall.frag",
|
2016-03-05 00:22:34 +03:00
|
|
|
"spv.newTexture.frag",
|
|
|
|
"spv.noDeadDecorations.vert",
|
|
|
|
"spv.nonSquare.vert",
|
|
|
|
"spv.Operations.frag",
|
|
|
|
"spv.intOps.vert",
|
|
|
|
"spv.precision.frag",
|
|
|
|
"spv.prepost.frag",
|
|
|
|
"spv.qualifiers.vert",
|
2016-04-14 11:53:07 +03:00
|
|
|
"spv.shaderBallot.comp",
|
2016-05-05 15:38:33 +03:00
|
|
|
"spv.shaderGroupVote.comp",
|
2016-03-05 00:22:34 +03:00
|
|
|
"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",
|
2016-07-26 21:50:38 +03:00
|
|
|
"spv.swizzleInversion.frag",
|
2016-03-05 00:22:34 +03:00
|
|
|
"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",
|
|
|
|
"spv.specConstantComposite.vert",
|
2016-05-04 21:35:16 +03:00
|
|
|
"spv.specConstantOperations.vert",
|
|
|
|
"spv.precise.tese",
|
|
|
|
"spv.precise.tesc",
|
2016-03-05 00:22:34 +03:00
|
|
|
})),
|
2016-05-16 19:50:30 +03:00
|
|
|
FileNameAsCustomTestSuffix
|
2016-03-05 00:22:34 +03:00
|
|
|
);
|
|
|
|
|
HLSL: Add location offsets per resource type
This PR adds the ability to offset sampler, texture, and UBO bindings
from provided base bindings, and to auto-number bindings that are not
provided with explicit register numbers. The mechanism works as
follows:
- Offsets may be given on the command line for all stages, or
individually for one or more single stages, in which case the
offset will be auto-selected according to the stage being
compiled. There is also an API to set them. The new command line
options are --shift-sampler-binding, --shift-texture-binding, and
--shift-UBO-binding.
- Uniforms which are not given explicit bindings in the source code
are auto-numbered if and only if they are in live code as
determined by the algorithm used to build the reflection
database, and the --auto-map-bindings option is given. This auto-numbering
avoids using any binding slots which were explicitly provided in
the code, whether or not that explicit use was live. E.g, "uniform
Texture1D foo : register(t3);" with --shift-texture-binding 10 will
reserve binding 13, whether or not foo is used in live code.
- Shorter synonyms for the command line options are available. See
the --help output.
The testing infrastructure is slightly extended to allow use of the
binding offset API, and two new tests spv.register.(no)autoassign.frag are
added for comparing the resulting SPIR-V.
2016-09-08 00:20:19 +03:00
|
|
|
// clang-format off
|
|
|
|
INSTANTIATE_TEST_CASE_P(
|
|
|
|
Hlsl, HlslSemantics,
|
|
|
|
::testing::ValuesIn(std::vector<IoMapData>{
|
|
|
|
{ "spv.register.autoassign.frag", "main_ep", 5, 10, 15, true },
|
|
|
|
{ "spv.register.noautoassign.frag", "main_ep", 5, 10, 15, false },
|
|
|
|
}),
|
|
|
|
FileNameAsCustomTestSuffixIoMap
|
|
|
|
);
|
|
|
|
|
2016-07-07 22:20:00 +03:00
|
|
|
// clang-format off
|
|
|
|
INSTANTIATE_TEST_CASE_P(
|
|
|
|
Glsl, CompileOpenGLToSpirvTest,
|
|
|
|
::testing::ValuesIn(std::vector<std::string>({
|
|
|
|
"spv.atomic.comp",
|
2016-07-08 02:46:42 +03:00
|
|
|
"spv.glFragColor.frag",
|
|
|
|
"spv.specConst.vert",
|
2016-07-07 22:20:00 +03:00
|
|
|
})),
|
|
|
|
FileNameAsCustomTestSuffix
|
|
|
|
);
|
|
|
|
|
2016-03-05 00:22:34 +03:00
|
|
|
INSTANTIATE_TEST_CASE_P(
|
|
|
|
Glsl, VulkanSemantics,
|
|
|
|
::testing::ValuesIn(std::vector<std::string>({
|
|
|
|
"vulkan.frag",
|
|
|
|
"vulkan.vert",
|
|
|
|
"vulkan.comp",
|
|
|
|
})),
|
2016-05-16 19:50:30 +03:00
|
|
|
FileNameAsCustomTestSuffix
|
2016-03-05 00:22:34 +03:00
|
|
|
);
|
2016-05-24 01:07:07 +03:00
|
|
|
|
2016-07-08 02:46:42 +03:00
|
|
|
INSTANTIATE_TEST_CASE_P(
|
|
|
|
Glsl, OpenGLSemantics,
|
|
|
|
::testing::ValuesIn(std::vector<std::string>({
|
|
|
|
"glspv.esversion.vert",
|
|
|
|
"glspv.version.frag",
|
|
|
|
"glspv.version.vert",
|
|
|
|
"glspv.frag",
|
|
|
|
"glspv.vert",
|
|
|
|
})),
|
|
|
|
FileNameAsCustomTestSuffix
|
|
|
|
);
|
|
|
|
|
2016-05-24 01:07:07 +03:00
|
|
|
INSTANTIATE_TEST_CASE_P(
|
|
|
|
Glsl, VulkanAstSemantics,
|
|
|
|
::testing::ValuesIn(std::vector<std::string>({
|
|
|
|
"vulkan.ast.vert",
|
|
|
|
})),
|
|
|
|
FileNameAsCustomTestSuffix
|
|
|
|
);
|
2016-03-05 00:22:34 +03:00
|
|
|
// clang-format on
|
|
|
|
|
|
|
|
} // anonymous namespace
|
|
|
|
} // namespace glslangtest
|