spirv-reader: update tests to valid SPIR-V

Bug: tint:765
Change-Id: I4312f9aa94fd813aeb9b388c10303f967057066f
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/49644
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: David Neto <dneto@google.com>
Auto-Submit: David Neto <dneto@google.com>
Reviewed-by: Alan Baker <alanbaker@google.com>
This commit is contained in:
David Neto 2021-05-05 16:12:32 +00:00 committed by Commit Bot service account
parent 6e2461096a
commit dee76fff44
2 changed files with 28 additions and 10 deletions

View File

@ -25,6 +25,15 @@ namespace {
using ::testing::Eq; using ::testing::Eq;
using ::testing::HasSubstr; using ::testing::HasSubstr;
std::string Preamble() {
return R"(
OpCapability Shader
OpMemoryModel Logical Simple
OpEntryPoint Fragment %100 "main"
OpExecutionMode %100 OriginUpperLeft
)";
}
std::string CommonTypes() { std::string CommonTypes() {
return R"( return R"(
%void = OpTypeVoid %void = OpTypeVoid
@ -45,7 +54,7 @@ std::string CommonTypes() {
using SpvParserTestMiscInstruction = SpvParserTest; using SpvParserTestMiscInstruction = SpvParserTest;
TEST_F(SpvParserTestMiscInstruction, OpUndef_BeforeFunction_Scalar) { TEST_F(SpvParserTestMiscInstruction, OpUndef_BeforeFunction_Scalar) {
const auto assembly = CommonTypes() + R"( const auto assembly = Preamble() + CommonTypes() + R"(
%1 = OpUndef %bool %1 = OpUndef %bool
%2 = OpUndef %uint %2 = OpUndef %uint
%3 = OpUndef %int %3 = OpUndef %int
@ -108,7 +117,7 @@ VariableDeclStatement{
} }
TEST_F(SpvParserTestMiscInstruction, OpUndef_BeforeFunction_Vector) { TEST_F(SpvParserTestMiscInstruction, OpUndef_BeforeFunction_Vector) {
const auto assembly = CommonTypes() + R"( const auto assembly = Preamble() + CommonTypes() + R"(
%4 = OpUndef %v2bool %4 = OpUndef %v2bool
%1 = OpUndef %v2uint %1 = OpUndef %v2uint
%2 = OpUndef %v2int %2 = OpUndef %v2int
@ -188,7 +197,7 @@ VariableDeclStatement{
} }
TEST_F(SpvParserTestMiscInstruction, OpUndef_InFunction_Scalar) { TEST_F(SpvParserTestMiscInstruction, OpUndef_InFunction_Scalar) {
const auto assembly = CommonTypes() + R"( const auto assembly = Preamble() + CommonTypes() + R"(
%100 = OpFunction %void None %voidfn %100 = OpFunction %void None %voidfn
%entry = OpLabel %entry = OpLabel
%1 = OpUndef %bool %1 = OpUndef %bool
@ -251,7 +260,7 @@ VariableDeclStatement{
} }
TEST_F(SpvParserTestMiscInstruction, OpUndef_InFunction_Vector) { TEST_F(SpvParserTestMiscInstruction, OpUndef_InFunction_Vector) {
const auto assembly = CommonTypes() + R"( const auto assembly = Preamble() + CommonTypes() + R"(
%100 = OpFunction %void None %voidfn %100 = OpFunction %void None %voidfn
%entry = OpLabel %entry = OpLabel
%1 = OpUndef %v2uint %1 = OpUndef %v2uint
@ -314,7 +323,7 @@ VariableDeclStatement{
} }
TEST_F(SpvParserTestMiscInstruction, OpUndef_InFunction_Matrix) { TEST_F(SpvParserTestMiscInstruction, OpUndef_InFunction_Matrix) {
const auto assembly = CommonTypes() + R"( const auto assembly = Preamble() + CommonTypes() + R"(
%mat = OpTypeMatrix %v2float 2 %mat = OpTypeMatrix %v2float 2
%100 = OpFunction %void None %voidfn %100 = OpFunction %void None %voidfn
@ -355,7 +364,7 @@ TEST_F(SpvParserTestMiscInstruction, OpUndef_InFunction_Matrix) {
} }
TEST_F(SpvParserTestMiscInstruction, OpUndef_InFunction_Array) { TEST_F(SpvParserTestMiscInstruction, OpUndef_InFunction_Array) {
const auto assembly = CommonTypes() + R"( const auto assembly = Preamble() + CommonTypes() + R"(
%uint_2 = OpConstant %uint 2 %uint_2 = OpConstant %uint 2
%arr = OpTypeArray %uint %uint_2 %arr = OpTypeArray %uint %uint_2
@ -389,7 +398,7 @@ TEST_F(SpvParserTestMiscInstruction, OpUndef_InFunction_Array) {
} }
TEST_F(SpvParserTestMiscInstruction, OpUndef_InFunction_Struct) { TEST_F(SpvParserTestMiscInstruction, OpUndef_InFunction_Struct) {
const auto assembly = CommonTypes() + R"( const auto assembly = Preamble() + CommonTypes() + R"(
%strct = OpTypeStruct %bool %uint %int %float %strct = OpTypeStruct %bool %uint %int %float
%100 = OpFunction %void None %voidfn %100 = OpFunction %void None %voidfn
@ -424,7 +433,7 @@ TEST_F(SpvParserTestMiscInstruction, OpUndef_InFunction_Struct) {
} }
TEST_F(SpvParserTestMiscInstruction, OpNop) { TEST_F(SpvParserTestMiscInstruction, OpNop) {
const auto assembly = CommonTypes() + R"( const auto assembly = Preamble() + CommonTypes() + R"(
%100 = OpFunction %void None %voidfn %100 = OpFunction %void None %voidfn
%entry = OpLabel %entry = OpLabel
OpNop OpNop
@ -452,7 +461,7 @@ using SpvParserSwizzleTest =
TEST_P(SpvParserSwizzleTest, Sample) { TEST_P(SpvParserSwizzleTest, Sample) {
// We need a function so we can get a FunctionEmitter. // We need a function so we can get a FunctionEmitter.
const auto assembly = CommonTypes() + R"( const auto assembly = Preamble() + CommonTypes() + R"(
%100 = OpFunction %void None %voidfn %100 = OpFunction %void None %voidfn
%entry = OpLabel %entry = OpLabel
OpReturn OpReturn

View File

@ -33,10 +33,18 @@ std::string Preamble() {
OpCapability Sampled1D OpCapability Sampled1D
OpCapability Image1D OpCapability Image1D
OpCapability StorageImageExtendedFormats OpCapability StorageImageExtendedFormats
OpCapability ImageQuery
OpMemoryModel Logical Simple OpMemoryModel Logical Simple
)"; )";
} }
std::string FragMain() {
return R"(
OpEntryPoint Fragment %main "main" ; assume no IO
OpExecutionMode %main OriginUpperLeft
)";
}
std::string CommonBasicTypes() { std::string CommonBasicTypes() {
return R"( return R"(
%void = OpTypeVoid %void = OpTypeVoid
@ -811,7 +819,7 @@ using SpvParserTest_RegisterHandleUsage_SampledImage =
SpvParserTestBase<::testing::TestWithParam<UsageImageAccessCase>>; SpvParserTestBase<::testing::TestWithParam<UsageImageAccessCase>>;
TEST_P(SpvParserTest_RegisterHandleUsage_SampledImage, Variable) { TEST_P(SpvParserTest_RegisterHandleUsage_SampledImage, Variable) {
const auto assembly = Preamble() + CommonTypes() + R"( const auto assembly = Preamble() + FragMain() + CommonTypes() + R"(
%si_ty = OpTypeSampledImage %f_texture_2d %si_ty = OpTypeSampledImage %f_texture_2d
%coords = OpConstantNull %v2float %coords = OpConstantNull %v2float
@ -1098,6 +1106,7 @@ using SpvParserTest_DeclUnderspecifiedHandle =
TEST_P(SpvParserTest_DeclUnderspecifiedHandle, Variable) { TEST_P(SpvParserTest_DeclUnderspecifiedHandle, Variable) {
const auto assembly = Preamble() + R"( const auto assembly = Preamble() + R"(
OpEntryPoint GLCompute %main "main"
OpDecorate %10 DescriptorSet 0 OpDecorate %10 DescriptorSet 0
OpDecorate %10 Binding 0 OpDecorate %10 Binding 0
)" + GetParam().decorations + )" + GetParam().decorations +