mirror of
https://github.com/KhronosGroup/SPIRV-Tools
synced 2024-12-24 00:40:14 +00:00
Add tests to validate allowed lengths of int and floats for WebGPU (#2289)
Fixes #2277
This commit is contained in:
parent
83bfdc976a
commit
3109ca16b0
@ -36,6 +36,24 @@ std::string HeaderWith(std::string cap) {
|
||||
cap + " OpMemoryModel Logical GLSL450 ";
|
||||
}
|
||||
|
||||
std::string WebGPUHeaderWith(std::string cap) {
|
||||
return R"(
|
||||
OpCapability Shader
|
||||
OpCapability )" +
|
||||
cap + R"(
|
||||
OpCapability VulkanMemoryModelKHR
|
||||
OpExtension "SPV_KHR_vulkan_memory_model"
|
||||
OpMemoryModel Logical VulkanKHR
|
||||
)";
|
||||
}
|
||||
|
||||
std::string webgpu_header = R"(
|
||||
OpCapability Shader
|
||||
OpCapability VulkanMemoryModelKHR
|
||||
OpExtension "SPV_KHR_vulkan_memory_model"
|
||||
OpMemoryModel Logical VulkanKHR
|
||||
)";
|
||||
|
||||
std::string header = R"(
|
||||
OpCapability Shader
|
||||
OpCapability Linkage
|
||||
@ -249,6 +267,18 @@ TEST_F(ValidateData, int8_with_storage_push_constant_8_good) {
|
||||
EXPECT_EQ(SPV_SUCCESS, ValidateInstructions()) << getDiagnosticString();
|
||||
}
|
||||
|
||||
TEST_F(ValidateData, webgpu_int8_bad) {
|
||||
std::string str = WebGPUHeaderWith("Int8") + "%2 = OpTypeInt 8 0";
|
||||
CompileSuccessfully(str.c_str(), SPV_ENV_WEBGPU_0);
|
||||
ASSERT_EQ(SPV_ERROR_INVALID_CAPABILITY,
|
||||
ValidateInstructions(SPV_ENV_WEBGPU_0));
|
||||
EXPECT_THAT(
|
||||
getDiagnosticString(),
|
||||
HasSubstr("Capability Int8 is not allowed by WebGPU specification (or "
|
||||
"requires extension)\n"
|
||||
" OpCapability Int8\n"));
|
||||
}
|
||||
|
||||
TEST_F(ValidateData, int16_good) {
|
||||
std::string str = header_with_int16 + "%2 = OpTypeInt 16 1";
|
||||
CompileSuccessfully(str.c_str());
|
||||
@ -308,6 +338,34 @@ TEST_F(ValidateData, int16_bad) {
|
||||
EXPECT_THAT(getDiagnosticString(), HasSubstr(missing_int16_cap_error));
|
||||
}
|
||||
|
||||
TEST_F(ValidateData, webgpu_int16_bad) {
|
||||
std::string str = WebGPUHeaderWith("Int16") + "%2 = OpTypeInt 16 1";
|
||||
CompileSuccessfully(str.c_str(), SPV_ENV_WEBGPU_0);
|
||||
ASSERT_EQ(SPV_ERROR_INVALID_CAPABILITY,
|
||||
ValidateInstructions(SPV_ENV_WEBGPU_0));
|
||||
EXPECT_THAT(
|
||||
getDiagnosticString(),
|
||||
HasSubstr("Capability Int16 is not allowed by WebGPU specification (or "
|
||||
"requires extension)\n"
|
||||
" OpCapability Int16\n"));
|
||||
}
|
||||
|
||||
TEST_F(ValidateData, webgpu_int32_good) {
|
||||
std::string str = webgpu_header + R"(
|
||||
OpEntryPoint Fragment %func "func"
|
||||
OpExecutionMode %func OriginUpperLeft
|
||||
%uint_t = OpTypeInt 32 0
|
||||
%void = OpTypeVoid
|
||||
%func_t = OpTypeFunction %void
|
||||
%func = OpFunction %void None %func_t
|
||||
%1 = OpLabel
|
||||
OpReturn
|
||||
OpFunctionEnd
|
||||
)";
|
||||
CompileSuccessfully(str.c_str(), SPV_ENV_WEBGPU_0);
|
||||
ASSERT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_WEBGPU_0));
|
||||
}
|
||||
|
||||
TEST_F(ValidateData, int64_good) {
|
||||
std::string str = header_with_int64 + "%2 = OpTypeInt 64 1";
|
||||
CompileSuccessfully(str.c_str());
|
||||
@ -321,6 +379,18 @@ TEST_F(ValidateData, int64_bad) {
|
||||
EXPECT_THAT(getDiagnosticString(), HasSubstr(missing_int64_cap_error));
|
||||
}
|
||||
|
||||
TEST_F(ValidateData, webgpu_int64_bad) {
|
||||
std::string str = WebGPUHeaderWith("Int64") + "%2 = OpTypeInt 64 1";
|
||||
CompileSuccessfully(str.c_str(), SPV_ENV_WEBGPU_0);
|
||||
ASSERT_EQ(SPV_ERROR_INVALID_CAPABILITY,
|
||||
ValidateInstructions(SPV_ENV_WEBGPU_0));
|
||||
EXPECT_THAT(
|
||||
getDiagnosticString(),
|
||||
HasSubstr("Capability Int64 is not allowed by WebGPU specification (or "
|
||||
"requires extension)\n"
|
||||
" OpCapability Int64\n"));
|
||||
}
|
||||
|
||||
// Number of bits in an integer may be only one of: {8,16,32,64}
|
||||
TEST_F(ValidateData, int_invalid_num_bits) {
|
||||
std::string str = header + "%2 = OpTypeInt 48 1";
|
||||
@ -348,6 +418,34 @@ TEST_F(ValidateData, float16_bad) {
|
||||
EXPECT_THAT(getDiagnosticString(), HasSubstr(missing_float16_cap_error));
|
||||
}
|
||||
|
||||
TEST_F(ValidateData, webgpu_float16_bad) {
|
||||
std::string str = WebGPUHeaderWith("Float16") + "%2 = OpTypeFloat 16";
|
||||
CompileSuccessfully(str.c_str(), SPV_ENV_WEBGPU_0);
|
||||
ASSERT_EQ(SPV_ERROR_INVALID_CAPABILITY,
|
||||
ValidateInstructions(SPV_ENV_WEBGPU_0));
|
||||
EXPECT_THAT(
|
||||
getDiagnosticString(),
|
||||
HasSubstr("Capability Float16 is not allowed by WebGPU specification (or "
|
||||
"requires extension)\n"
|
||||
" OpCapability Float16\n"));
|
||||
}
|
||||
|
||||
TEST_F(ValidateData, webgpu_float32_good) {
|
||||
std::string str = webgpu_header + R"(
|
||||
OpEntryPoint Fragment %func "func"
|
||||
OpExecutionMode %func OriginUpperLeft
|
||||
%float_t = OpTypeFloat 32
|
||||
%void = OpTypeVoid
|
||||
%func_t = OpTypeFunction %void
|
||||
%func = OpFunction %void None %func_t
|
||||
%1 = OpLabel
|
||||
OpReturn
|
||||
OpFunctionEnd
|
||||
)";
|
||||
CompileSuccessfully(str.c_str(), SPV_ENV_WEBGPU_0);
|
||||
ASSERT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_WEBGPU_0));
|
||||
}
|
||||
|
||||
TEST_F(ValidateData, float64_good) {
|
||||
std::string str = header_with_float64 + "%2 = OpTypeFloat 64";
|
||||
CompileSuccessfully(str.c_str());
|
||||
@ -361,6 +459,18 @@ TEST_F(ValidateData, float64_bad) {
|
||||
EXPECT_THAT(getDiagnosticString(), HasSubstr(missing_float64_cap_error));
|
||||
}
|
||||
|
||||
TEST_F(ValidateData, webgpu_float64_bad) {
|
||||
std::string str = WebGPUHeaderWith("Float64") + "%2 = OpTypeFloat 64";
|
||||
CompileSuccessfully(str.c_str(), SPV_ENV_WEBGPU_0);
|
||||
ASSERT_EQ(SPV_ERROR_INVALID_CAPABILITY,
|
||||
ValidateInstructions(SPV_ENV_WEBGPU_0));
|
||||
EXPECT_THAT(
|
||||
getDiagnosticString(),
|
||||
HasSubstr("Capability Float64 is not allowed by WebGPU specification (or "
|
||||
"requires extension)\n"
|
||||
" OpCapability Float64\n"));
|
||||
}
|
||||
|
||||
// Number of bits in a float may be only one of: {16,32,64}
|
||||
TEST_F(ValidateData, float_invalid_num_bits) {
|
||||
std::string str = header + "%2 = OpTypeFloat 48";
|
||||
|
Loading…
Reference in New Issue
Block a user