summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorDavid Neto <dneto@google.com>2018-07-09 17:19:34 -0400
committerDavid Neto <dneto@google.com>2018-07-10 17:16:54 -0400
commitfec6315fadf4b57f9b342a870f498b87d245fd70 (patch)
tree53405d67d8173b8c952c8f41066f6f081d450737 /test
parenteb48263cc8764ccdf185b31b87d58e1bb0e0d748 (diff)
Vulkan permits non-monotonic offsets for block members
Other environments do not. Add tests for OpenGL 4.5 and SPIR-V universal 1.0 to ensure they still check monotonic layout. For universal 1.0, we're assuming it otherwise follows Vulkan rules for block layout. Fixes #1685
Diffstat (limited to 'test')
-rw-r--r--test/val/val_decoration_test.cpp74
1 files changed, 70 insertions, 4 deletions
diff --git a/test/val/val_decoration_test.cpp b/test/val/val_decoration_test.cpp
index 0c591aa1..7574173a 100644
--- a/test/val/val_decoration_test.cpp
+++ b/test/val/val_decoration_test.cpp
@@ -2264,7 +2264,7 @@ TEST_F(ValidateDecorations,
"offset 4 overlaps previous member ending at offset 15"));
}
-TEST_F(ValidateDecorations, BlockLayoutOffsetOutOfOrderBad) {
+TEST_F(ValidateDecorations, BlockLayoutOffsetOutOfOrderBadUniversal1_0) {
string spirv = R"(
OpCapability Shader
%1 = OpExtInstImport "GLSL.std.450"
@@ -2289,13 +2289,79 @@ TEST_F(ValidateDecorations, BlockLayoutOffsetOutOfOrderBad) {
)";
CompileSuccessfully(spirv);
- EXPECT_EQ(SPV_ERROR_INVALID_ID, ValidateAndRetrieveValidationState());
+ EXPECT_EQ(SPV_ERROR_INVALID_ID,
+ ValidateAndRetrieveValidationState(SPV_ENV_UNIVERSAL_1_0));
EXPECT_THAT(
getDiagnosticString(),
HasSubstr(
"Structure id 3 decorated as Block for variable in Uniform storage "
- "class must follow standard uniform buffer layout rules: member 1 at "
- "offset 0 has a lower offset than member 0"));
+ "class must follow standard uniform buffer layout rules: member 0 at "
+ "offset 4 has a higher offset than member 1 at offset 0"));
+}
+
+TEST_F(ValidateDecorations, BlockLayoutOffsetOutOfOrderBadOpenGL4_5) {
+ string spirv = R"(
+ OpCapability Shader
+ %1 = OpExtInstImport "GLSL.std.450"
+ OpMemoryModel Logical GLSL450
+ OpEntryPoint GLCompute %main "main"
+ OpExecutionMode %main LocalSize 1 1 1
+ OpMemberDecorate %Outer 0 Offset 4
+ OpMemberDecorate %Outer 1 Offset 0
+ OpDecorate %Outer Block
+ OpDecorate %O DescriptorSet 0
+ OpDecorate %O Binding 0
+ %void = OpTypeVoid
+ %3 = OpTypeFunction %void
+ %uint = OpTypeInt 32 0
+ %Outer = OpTypeStruct %uint %uint
+%_ptr_Uniform_Outer = OpTypePointer Uniform %Outer
+ %O = OpVariable %_ptr_Uniform_Outer Uniform
+ %main = OpFunction %void None %3
+ %5 = OpLabel
+ OpReturn
+ OpFunctionEnd
+ )";
+
+ CompileSuccessfully(spirv);
+ EXPECT_EQ(SPV_ERROR_INVALID_ID,
+ ValidateAndRetrieveValidationState(SPV_ENV_OPENGL_4_5));
+ EXPECT_THAT(
+ getDiagnosticString(),
+ HasSubstr(
+ "Structure id 3 decorated as Block for variable in Uniform storage "
+ "class must follow standard uniform buffer layout rules: member 0 at "
+ "offset 4 has a higher offset than member 1 at offset 0"));
+}
+
+TEST_F(ValidateDecorations, BlockLayoutOffsetOutOfOrderGoodVulkan1_1) {
+ string spirv = R"(
+ OpCapability Shader
+ %1 = OpExtInstImport "GLSL.std.450"
+ OpMemoryModel Logical GLSL450
+ OpEntryPoint GLCompute %main "main"
+ OpExecutionMode %main LocalSize 1 1 1
+ OpMemberDecorate %Outer 0 Offset 4
+ OpMemberDecorate %Outer 1 Offset 0
+ OpDecorate %Outer Block
+ OpDecorate %O DescriptorSet 0
+ OpDecorate %O Binding 0
+ %void = OpTypeVoid
+ %3 = OpTypeFunction %void
+ %uint = OpTypeInt 32 0
+ %Outer = OpTypeStruct %uint %uint
+%_ptr_Uniform_Outer = OpTypePointer Uniform %Outer
+ %O = OpVariable %_ptr_Uniform_Outer Uniform
+ %main = OpFunction %void None %3
+ %5 = OpLabel
+ OpReturn
+ OpFunctionEnd
+ )";
+
+ CompileSuccessfully(spirv);
+ EXPECT_EQ(SPV_SUCCESS, ValidateAndRetrieveValidationState(SPV_ENV_VULKAN_1_1))
+ << getDiagnosticString();
+ EXPECT_THAT(getDiagnosticString(), Eq(""));
}
TEST_F(ValidateDecorations, BlockLayoutOffsetOverlapBad) {