Skip to content

Commit 92f3f10

Browse files
spirv-val: Add Location Interpolation check
1 parent 9fa14b9 commit 92f3f10

1 file changed

Lines changed: 212 additions & 0 deletions

File tree

test/val/val_interfaces_test.cpp

Lines changed: 212 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1807,6 +1807,218 @@ OpFunctionEnd
18071807
EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_3));
18081808
}
18091809

1810+
TEST_F(ValidateInterfacesTest, InterpolationOverlapVariableSuccess) {
1811+
const std::string text = R"(
1812+
OpCapability Shader
1813+
OpMemoryModel Logical GLSL450
1814+
OpEntryPoint Fragment %main "main" %cFlat %cFlat2 %cSmooth
1815+
OpExecutionMode %main OriginUpperLeft
1816+
OpDecorate %cFlat Flat
1817+
OpDecorate %cFlat Location 0
1818+
OpDecorate %cFlat Component 0
1819+
OpDecorate %cFlat2 Flat
1820+
OpDecorate %cFlat2 Location 0
1821+
OpDecorate %cFlat2 Component 1
1822+
OpDecorate %cSmooth Centroid
1823+
OpDecorate %cSmooth Location 1
1824+
OpDecorate %cSmooth Component 0
1825+
%void = OpTypeVoid
1826+
%4 = OpTypeFunction %void
1827+
%float = OpTypeFloat 32
1828+
%in_ptr = OpTypePointer Input %float
1829+
%cFlat = OpVariable %in_ptr Input
1830+
%cFlat2 = OpVariable %in_ptr Input
1831+
%cSmooth = OpVariable %in_ptr Input
1832+
%main = OpFunction %void None %4
1833+
%6 = OpLabel
1834+
OpReturn
1835+
OpFunctionEnd
1836+
)";
1837+
1838+
CompileSuccessfully(text, SPV_ENV_VULKAN_1_0);
1839+
EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_0));
1840+
}
1841+
1842+
TEST_F(ValidateInterfacesTest, InterpolationOverlapVariableBad) {
1843+
const std::string text = R"(
1844+
OpCapability Shader
1845+
OpMemoryModel Logical GLSL450
1846+
OpEntryPoint Fragment %main "main" %cFlat %cSmooth
1847+
OpExecutionMode %main OriginUpperLeft
1848+
OpDecorate %cFlat Flat
1849+
OpDecorate %cFlat Location 0
1850+
OpDecorate %cFlat Component 0
1851+
OpDecorate %cSmooth Centroid
1852+
OpDecorate %cSmooth Location 0
1853+
OpDecorate %cSmooth Component 1
1854+
%void = OpTypeVoid
1855+
%4 = OpTypeFunction %void
1856+
%float = OpTypeFloat 32
1857+
%in_ptr = OpTypePointer Input %float
1858+
%cFlat = OpVariable %in_ptr Input
1859+
%cSmooth = OpVariable %in_ptr Input
1860+
%main = OpFunction %void None %4
1861+
%6 = OpLabel
1862+
OpReturn
1863+
OpFunctionEnd
1864+
)";
1865+
1866+
CompileSuccessfully(text, SPV_ENV_VULKAN_1_0);
1867+
EXPECT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions(SPV_ENV_VULKAN_1_0));
1868+
EXPECT_THAT(
1869+
getDiagnosticString(),
1870+
HasSubstr("Location 0 has conflicting Interpolation decorations"));
1871+
}
1872+
1873+
TEST_F(ValidateInterfacesTest, InterpolationOverlapBlockSuccess) {
1874+
const std::string text = R"(
1875+
OpCapability Shader
1876+
OpMemoryModel Logical GLSL450
1877+
OpEntryPoint Fragment %main "main" %in
1878+
OpExecutionMode %main OriginUpperLeft
1879+
OpDecorate %struct Block
1880+
OpMemberDecorate %struct 0 Flat
1881+
OpMemberDecorate %struct 0 Location 0
1882+
OpMemberDecorate %struct 0 Component 0
1883+
OpMemberDecorate %struct 2 Flat
1884+
OpMemberDecorate %struct 2 Location 0
1885+
OpMemberDecorate %struct 2 Component 1
1886+
OpMemberDecorate %struct 1 Centroid
1887+
OpMemberDecorate %struct 1 Location 1
1888+
OpMemberDecorate %struct 1 Component 0
1889+
%void = OpTypeVoid
1890+
%float = OpTypeFloat 32
1891+
%struct = OpTypeStruct %float %float %float
1892+
%in_ptr = OpTypePointer Input %struct
1893+
%in = OpVariable %in_ptr Input
1894+
%void_fn = OpTypeFunction %void
1895+
%main = OpFunction %void None %void_fn
1896+
%entry = OpLabel
1897+
OpReturn
1898+
OpFunctionEnd
1899+
)";
1900+
1901+
CompileSuccessfully(text, SPV_ENV_VULKAN_1_0);
1902+
EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_0));
1903+
}
1904+
1905+
TEST_F(ValidateInterfacesTest, InterpolationOverlapBlockBad) {
1906+
const std::string text = R"(
1907+
OpCapability Shader
1908+
OpMemoryModel Logical GLSL450
1909+
OpEntryPoint Fragment %main "main" %in
1910+
OpExecutionMode %main OriginUpperLeft
1911+
OpDecorate %struct Block
1912+
OpMemberDecorate %struct 0 Flat
1913+
OpMemberDecorate %struct 0 Location 0
1914+
OpMemberDecorate %struct 0 Component 0
1915+
OpMemberDecorate %struct 1 Centroid
1916+
OpMemberDecorate %struct 1 Location 0
1917+
OpMemberDecorate %struct 1 Component 1
1918+
%void = OpTypeVoid
1919+
%float = OpTypeFloat 32
1920+
%struct = OpTypeStruct %float %float
1921+
%in_ptr = OpTypePointer Input %struct
1922+
%in = OpVariable %in_ptr Input
1923+
%void_fn = OpTypeFunction %void
1924+
%main = OpFunction %void None %void_fn
1925+
%entry = OpLabel
1926+
OpReturn
1927+
OpFunctionEnd
1928+
)";
1929+
1930+
CompileSuccessfully(text, SPV_ENV_VULKAN_1_0);
1931+
EXPECT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions(SPV_ENV_VULKAN_1_0));
1932+
EXPECT_THAT(
1933+
getDiagnosticString(),
1934+
HasSubstr("Location 0 has conflicting Interpolation decorations"));
1935+
}
1936+
1937+
TEST_F(ValidateInterfacesTest, InterpolationOverlapBlockAndVariable) {
1938+
const std::string text = R"(
1939+
OpCapability Shader
1940+
OpMemoryModel Logical GLSL450
1941+
OpEntryPoint Fragment %main "main" %in_s %in_f
1942+
OpExecutionMode %main OriginUpperLeft
1943+
OpDecorate %struct Block
1944+
OpMemberDecorate %struct 0 Flat
1945+
OpMemberDecorate %struct 0 Location 0
1946+
OpMemberDecorate %struct 0 Component 0
1947+
OpDecorate %in_f Centroid
1948+
OpDecorate %in_f Location 0
1949+
OpDecorate %in_f Component 1
1950+
%void = OpTypeVoid
1951+
%float = OpTypeFloat 32
1952+
%struct = OpTypeStruct %float
1953+
%s_ptr = OpTypePointer Input %struct
1954+
%f_ptr = OpTypePointer Input %float
1955+
%in_s = OpVariable %s_ptr Input
1956+
%in_f = OpVariable %f_ptr Input
1957+
%void_fn = OpTypeFunction %void
1958+
%main = OpFunction %void None %void_fn
1959+
%entry = OpLabel
1960+
OpReturn
1961+
OpFunctionEnd
1962+
)";
1963+
1964+
CompileSuccessfully(text, SPV_ENV_VULKAN_1_0);
1965+
EXPECT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions(SPV_ENV_VULKAN_1_0));
1966+
EXPECT_THAT(
1967+
getDiagnosticString(),
1968+
HasSubstr("Location 0 has conflicting Interpolation decorations"));
1969+
}
1970+
1971+
TEST_F(ValidateInterfacesTest, InterpolationOverlapSingleVariable) {
1972+
const std::string text = R"(
1973+
OpCapability Shader
1974+
OpMemoryModel Logical GLSL450
1975+
OpEntryPoint Fragment %main "main" %in_f
1976+
OpExecutionMode %main OriginUpperLeft
1977+
OpDecorate %in_f Flat
1978+
OpDecorate %in_f Centroid
1979+
OpDecorate %in_f Location 0
1980+
%void = OpTypeVoid
1981+
%float = OpTypeFloat 32
1982+
%f_ptr = OpTypePointer Input %float
1983+
%in_f = OpVariable %f_ptr Input
1984+
%void_fn = OpTypeFunction %void
1985+
%main = OpFunction %void None %void_fn
1986+
%entry = OpLabel
1987+
OpReturn
1988+
OpFunctionEnd
1989+
)";
1990+
1991+
CompileSuccessfully(text, SPV_ENV_VULKAN_1_0);
1992+
EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_0));
1993+
}
1994+
1995+
TEST_F(ValidateInterfacesTest, InterpolationOverlapVariableWithoutDecoration) {
1996+
const std::string text = R"(
1997+
OpCapability Shader
1998+
OpMemoryModel Logical GLSL450
1999+
OpEntryPoint Fragment %main "main" %in_a %in_b
2000+
OpExecutionMode %main OriginUpperLeft
2001+
OpDecorate %in_a Flat
2002+
OpDecorate %in_a Location 0
2003+
OpDecorate %in_a Component 0
2004+
OpDecorate %in_b Location 0
2005+
OpDecorate %in_b Component 1
2006+
%void = OpTypeVoid
2007+
%float = OpTypeFloat 32
2008+
%f_ptr = OpTypePointer Input %float
2009+
%in_a = OpVariable %f_ptr Input
2010+
%in_b = OpVariable %f_ptr Input
2011+
%void_fn = OpTypeFunction %void
2012+
%main = OpFunction %void None %void_fn
2013+
%entry = OpLabel
2014+
OpReturn
2015+
OpFunctionEnd
2016+
)";
2017+
2018+
CompileSuccessfully(text, SPV_ENV_VULKAN_1_0);
2019+
EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_0));
2020+
}
2021+
18102022
} // namespace
18112023
} // namespace val
18122024
} // namespace spvtools

0 commit comments

Comments
 (0)