mirror of
https://github.com/KhronosGroup/SPIRV-Tools
synced 2024-11-22 19:50:05 +00:00
Update structure layout validation (#4876)
* Uniform block layout rules for matrices should use extended layouts by default
This commit is contained in:
parent
8dc0030ecb
commit
4773879b68
@ -226,6 +226,7 @@ uint32_t getBaseAlignment(uint32_t member_id, bool roundUp,
|
|||||||
baseAlignment =
|
baseAlignment =
|
||||||
componentAlignment * (num_columns == 3 ? 4 : num_columns);
|
componentAlignment * (num_columns == 3 ? 4 : num_columns);
|
||||||
}
|
}
|
||||||
|
if (roundUp) baseAlignment = align(baseAlignment, 16u);
|
||||||
} break;
|
} break;
|
||||||
case SpvOpTypeArray:
|
case SpvOpTypeArray:
|
||||||
case SpvOpTypeRuntimeArray:
|
case SpvOpTypeRuntimeArray:
|
||||||
|
@ -8897,6 +8897,7 @@ TEST_F(InstBindlessTest, UniformMatrixRefColumnMajor) {
|
|||||||
)";
|
)";
|
||||||
|
|
||||||
SetTargetEnv(SPV_ENV_VULKAN_1_2);
|
SetTargetEnv(SPV_ENV_VULKAN_1_2);
|
||||||
|
ValidatorOptions()->uniform_buffer_standard_layout = true;
|
||||||
SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
|
SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
|
||||||
SinglePassRunAndMatch<InstBindlessCheckPass>(text, true, 7u, 23u, false,
|
SinglePassRunAndMatch<InstBindlessCheckPass>(text, true, 7u, 23u, false,
|
||||||
false, true, false, true);
|
false, true, false, true);
|
||||||
|
@ -8736,6 +8736,141 @@ TEST_F(ValidateDecorations, NVBindlessSamplerArrayInBlock) {
|
|||||||
EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_UNIVERSAL_1_3));
|
EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_UNIVERSAL_1_3));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_F(ValidateDecorations, Std140ColMajorMat2x2) {
|
||||||
|
const std::string spirv = R"(
|
||||||
|
OpCapability Shader
|
||||||
|
OpMemoryModel Logical GLSL450
|
||||||
|
OpEntryPoint GLCompute %main "main"
|
||||||
|
OpExecutionMode %main LocalSize 1 1 1
|
||||||
|
OpDecorate %block Block
|
||||||
|
OpMemberDecorate %block 0 Offset 0
|
||||||
|
OpMemberDecorate %block 0 ColMajor
|
||||||
|
OpMemberDecorate %block 0 MatrixStride 8
|
||||||
|
OpDecorate %var DescriptorSet 0
|
||||||
|
OpDecorate %var Binding 0
|
||||||
|
%void = OpTypeVoid
|
||||||
|
%void_fn = OpTypeFunction %void
|
||||||
|
%float = OpTypeFloat 32
|
||||||
|
%float2 = OpTypeVector %float 2
|
||||||
|
%matrix = OpTypeMatrix %float2 2
|
||||||
|
%block = OpTypeStruct %matrix
|
||||||
|
%ptr_block = OpTypePointer Uniform %block
|
||||||
|
%var = OpVariable %ptr_block Uniform
|
||||||
|
%main = OpFunction %void None %void_fn
|
||||||
|
%entry = OpLabel
|
||||||
|
OpReturn
|
||||||
|
OpFunctionEnd
|
||||||
|
)";
|
||||||
|
|
||||||
|
CompileSuccessfully(spirv, SPV_ENV_VULKAN_1_0);
|
||||||
|
EXPECT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions(SPV_ENV_VULKAN_1_0));
|
||||||
|
EXPECT_THAT(
|
||||||
|
getDiagnosticString(),
|
||||||
|
HasSubstr(
|
||||||
|
"member 0 is a matrix with stride 8 not satisfying alignment to 16"));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(ValidateDecorations, Std140RowMajorMat2x2) {
|
||||||
|
const std::string spirv = R"(
|
||||||
|
OpCapability Shader
|
||||||
|
OpMemoryModel Logical GLSL450
|
||||||
|
OpEntryPoint GLCompute %main "main"
|
||||||
|
OpExecutionMode %main LocalSize 1 1 1
|
||||||
|
OpDecorate %block Block
|
||||||
|
OpMemberDecorate %block 0 Offset 0
|
||||||
|
OpMemberDecorate %block 0 RowMajor
|
||||||
|
OpMemberDecorate %block 0 MatrixStride 8
|
||||||
|
OpDecorate %var DescriptorSet 0
|
||||||
|
OpDecorate %var Binding 0
|
||||||
|
%void = OpTypeVoid
|
||||||
|
%void_fn = OpTypeFunction %void
|
||||||
|
%float = OpTypeFloat 32
|
||||||
|
%float2 = OpTypeVector %float 2
|
||||||
|
%matrix = OpTypeMatrix %float2 2
|
||||||
|
%block = OpTypeStruct %matrix
|
||||||
|
%ptr_block = OpTypePointer Uniform %block
|
||||||
|
%var = OpVariable %ptr_block Uniform
|
||||||
|
%main = OpFunction %void None %void_fn
|
||||||
|
%entry = OpLabel
|
||||||
|
OpReturn
|
||||||
|
OpFunctionEnd
|
||||||
|
)";
|
||||||
|
|
||||||
|
CompileSuccessfully(spirv, SPV_ENV_VULKAN_1_0);
|
||||||
|
EXPECT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions(SPV_ENV_VULKAN_1_0));
|
||||||
|
EXPECT_THAT(
|
||||||
|
getDiagnosticString(),
|
||||||
|
HasSubstr(
|
||||||
|
"member 0 is a matrix with stride 8 not satisfying alignment to 16"));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(ValidateDecorations, Std140ColMajorMat4x2) {
|
||||||
|
const std::string spirv = R"(
|
||||||
|
OpCapability Shader
|
||||||
|
OpMemoryModel Logical GLSL450
|
||||||
|
OpEntryPoint GLCompute %main "main"
|
||||||
|
OpExecutionMode %main LocalSize 1 1 1
|
||||||
|
OpDecorate %block Block
|
||||||
|
OpMemberDecorate %block 0 Offset 0
|
||||||
|
OpMemberDecorate %block 0 ColMajor
|
||||||
|
OpMemberDecorate %block 0 MatrixStride 8
|
||||||
|
OpDecorate %var DescriptorSet 0
|
||||||
|
OpDecorate %var Binding 0
|
||||||
|
%void = OpTypeVoid
|
||||||
|
%void_fn = OpTypeFunction %void
|
||||||
|
%float = OpTypeFloat 32
|
||||||
|
%float2 = OpTypeVector %float 2
|
||||||
|
%matrix = OpTypeMatrix %float2 4
|
||||||
|
%block = OpTypeStruct %matrix
|
||||||
|
%ptr_block = OpTypePointer Uniform %block
|
||||||
|
%var = OpVariable %ptr_block Uniform
|
||||||
|
%main = OpFunction %void None %void_fn
|
||||||
|
%entry = OpLabel
|
||||||
|
OpReturn
|
||||||
|
OpFunctionEnd
|
||||||
|
)";
|
||||||
|
|
||||||
|
CompileSuccessfully(spirv, SPV_ENV_VULKAN_1_0);
|
||||||
|
EXPECT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions(SPV_ENV_VULKAN_1_0));
|
||||||
|
EXPECT_THAT(
|
||||||
|
getDiagnosticString(),
|
||||||
|
HasSubstr(
|
||||||
|
"member 0 is a matrix with stride 8 not satisfying alignment to 16"));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(ValidateDecorations, Std140ColMajorMat2x3) {
|
||||||
|
const std::string spirv = R"(
|
||||||
|
OpCapability Shader
|
||||||
|
OpMemoryModel Logical GLSL450
|
||||||
|
OpEntryPoint GLCompute %main "main"
|
||||||
|
OpExecutionMode %main LocalSize 1 1 1
|
||||||
|
OpDecorate %block Block
|
||||||
|
OpMemberDecorate %block 0 Offset 0
|
||||||
|
OpMemberDecorate %block 0 ColMajor
|
||||||
|
OpMemberDecorate %block 0 MatrixStride 12
|
||||||
|
OpDecorate %var DescriptorSet 0
|
||||||
|
OpDecorate %var Binding 0
|
||||||
|
%void = OpTypeVoid
|
||||||
|
%void_fn = OpTypeFunction %void
|
||||||
|
%float = OpTypeFloat 32
|
||||||
|
%float3 = OpTypeVector %float 3
|
||||||
|
%matrix = OpTypeMatrix %float3 2
|
||||||
|
%block = OpTypeStruct %matrix
|
||||||
|
%ptr_block = OpTypePointer Uniform %block
|
||||||
|
%var = OpVariable %ptr_block Uniform
|
||||||
|
%main = OpFunction %void None %void_fn
|
||||||
|
%entry = OpLabel
|
||||||
|
OpReturn
|
||||||
|
OpFunctionEnd
|
||||||
|
)";
|
||||||
|
|
||||||
|
CompileSuccessfully(spirv, SPV_ENV_VULKAN_1_0);
|
||||||
|
EXPECT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions(SPV_ENV_VULKAN_1_0));
|
||||||
|
EXPECT_THAT(getDiagnosticString(),
|
||||||
|
HasSubstr("member 0 is a matrix with stride 12 not satisfying "
|
||||||
|
"alignment to 16"));
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
} // namespace val
|
} // namespace val
|
||||||
} // namespace spvtools
|
} // namespace spvtools
|
||||||
|
Loading…
Reference in New Issue
Block a user