| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286 |
- // Copyright (c) 2018 Google LLC.
- //
- // Licensed under the Apache License, Version 2.0 (the "License");
- // you may not use this file except in compliance with the License.
- // You may obtain a copy of the License at
- //
- // http://www.apache.org/licenses/LICENSE-2.0
- //
- // Unless required by applicable law or agreed to in writing, software
- // distributed under the License is distributed on an "AS IS" BASIS,
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- // See the License for the specific language governing permissions and
- // limitations under the License.
- #include <sstream>
- #include <string>
- #include <vector>
- #include "gmock/gmock.h"
- #include "source/spirv_target_env.h"
- #include "test/test_fixture.h"
- #include "test/unit_spirv.h"
- #include "test/val/val_fixtures.h"
- namespace spvtools {
- namespace val {
- namespace {
- using ::testing::Combine;
- using ::testing::HasSubstr;
- using ::testing::Values;
- using ::testing::ValuesIn;
- using ValidateMode = spvtest::ValidateBase<bool>;
- const std::string kVoidFunction = R"(%void = OpTypeVoid
- %void_fn = OpTypeFunction %void
- %main = OpFunction %void None %void_fn
- %entry = OpLabel
- OpReturn
- OpFunctionEnd
- )";
- TEST_F(ValidateMode, GLComputeNoMode) {
- const std::string spirv = R"(
- OpCapability Shader
- OpMemoryModel Logical GLSL450
- OpEntryPoint GLCompute %main "main"
- )" + kVoidFunction;
- CompileSuccessfully(spirv);
- EXPECT_THAT(SPV_SUCCESS, ValidateInstructions());
- }
- TEST_F(ValidateMode, GLComputeNoModeVulkan) {
- const std::string spirv = R"(
- OpCapability Shader
- OpMemoryModel Logical GLSL450
- OpEntryPoint GLCompute %main "main"
- )" + kVoidFunction;
- spv_target_env env = SPV_ENV_VULKAN_1_0;
- CompileSuccessfully(spirv, env);
- EXPECT_THAT(SPV_ERROR_INVALID_DATA, ValidateInstructions(env));
- EXPECT_THAT(getDiagnosticString(),
- AnyVUID("VUID-StandaloneSpirv-LocalSize-06426"));
- EXPECT_THAT(
- getDiagnosticString(),
- HasSubstr(
- "In the Vulkan environment, GLCompute execution model entry "
- "points require either the LocalSize or LocalSizeId execution mode "
- "or an object decorated with WorkgroupSize must be specified."));
- }
- TEST_F(ValidateMode, GLComputeNoModeVulkanWorkgroupSize) {
- const std::string spirv = R"(
- OpCapability Shader
- OpMemoryModel Logical GLSL450
- OpEntryPoint GLCompute %main "main"
- OpDecorate %int3_1 BuiltIn WorkgroupSize
- %int = OpTypeInt 32 0
- %int3 = OpTypeVector %int 3
- %int_1 = OpConstant %int 1
- %int3_1 = OpConstantComposite %int3 %int_1 %int_1 %int_1
- )" + kVoidFunction;
- spv_target_env env = SPV_ENV_VULKAN_1_0;
- CompileSuccessfully(spirv, env);
- EXPECT_THAT(SPV_SUCCESS, ValidateInstructions(env));
- }
- TEST_F(ValidateMode, GLComputeVulkanLocalSize) {
- const std::string spirv = R"(
- OpCapability Shader
- OpMemoryModel Logical GLSL450
- OpEntryPoint GLCompute %main "main"
- OpExecutionMode %main LocalSize 1 1 1
- )" + kVoidFunction;
- spv_target_env env = SPV_ENV_VULKAN_1_0;
- CompileSuccessfully(spirv, env);
- EXPECT_THAT(SPV_SUCCESS, ValidateInstructions(env));
- }
- TEST_F(ValidateMode, GLComputeVulkanLocalSizeIdBad) {
- const std::string spirv = R"(
- OpCapability Shader
- OpMemoryModel Logical GLSL450
- OpEntryPoint GLCompute %main "main"
- OpExecutionModeId %main LocalSizeId %int_1 %int_1 %int_1
- %int = OpTypeInt 32 0
- %int_1 = OpConstant %int 1
- )" + kVoidFunction;
- spv_target_env env = SPV_ENV_VULKAN_1_1; // need SPIR-V 1.2
- CompileSuccessfully(spirv, env);
- EXPECT_THAT(SPV_ERROR_INVALID_DATA, ValidateInstructions(env));
- EXPECT_THAT(
- getDiagnosticString(),
- HasSubstr("LocalSizeId mode is not allowed by the current environment."));
- }
- TEST_F(ValidateMode, GLComputeVulkanLocalSizeIdGood) {
- const std::string spirv = R"(
- OpCapability Shader
- OpMemoryModel Logical GLSL450
- OpEntryPoint GLCompute %main "main"
- OpExecutionModeId %main LocalSizeId %int_1 %int_1 %int_1
- %int = OpTypeInt 32 0
- %int_1 = OpConstant %int 1
- )" + kVoidFunction;
- spv_target_env env = SPV_ENV_VULKAN_1_1; // need SPIR-V 1.2
- CompileSuccessfully(spirv, env);
- spvValidatorOptionsSetAllowLocalSizeId(getValidatorOptions(), true);
- EXPECT_THAT(SPV_SUCCESS, ValidateInstructions(env));
- }
- TEST_F(ValidateMode, FragmentOriginLowerLeftVulkan) {
- const std::string spirv = R"(
- OpCapability Shader
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %main "main"
- OpExecutionMode %main OriginLowerLeft
- )" + kVoidFunction;
- spv_target_env env = SPV_ENV_VULKAN_1_0;
- CompileSuccessfully(spirv, env);
- EXPECT_THAT(SPV_ERROR_INVALID_DATA, ValidateInstructions(env));
- EXPECT_THAT(getDiagnosticString(),
- AnyVUID("VUID-StandaloneSpirv-OriginLowerLeft-04653"));
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("In the Vulkan environment, the OriginLowerLeft "
- "execution mode must not be used."));
- }
- TEST_F(ValidateMode, FragmentPixelCenterIntegerVulkan) {
- const std::string spirv = R"(
- OpCapability Shader
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %main "main"
- OpExecutionMode %main OriginUpperLeft
- OpExecutionMode %main PixelCenterInteger
- )" + kVoidFunction;
- spv_target_env env = SPV_ENV_VULKAN_1_0;
- CompileSuccessfully(spirv, env);
- EXPECT_THAT(SPV_ERROR_INVALID_DATA, ValidateInstructions(env));
- EXPECT_THAT(getDiagnosticString(),
- AnyVUID("VUID-StandaloneSpirv-PixelCenterInteger-04654"));
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("In the Vulkan environment, the PixelCenterInteger "
- "execution mode must not be used."));
- }
- TEST_F(ValidateMode, GeometryNoOutputMode) {
- const std::string spirv = R"(
- OpCapability Geometry
- OpMemoryModel Logical GLSL450
- OpEntryPoint Geometry %main "main"
- OpExecutionMode %main InputPoints
- )" + kVoidFunction;
- CompileSuccessfully(spirv);
- EXPECT_THAT(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Geometry execution model entry points must specify "
- "exactly one of OutputPoints, OutputLineStrip or "
- "OutputTriangleStrip execution modes."));
- }
- TEST_F(ValidateMode, GeometryNoInputMode) {
- const std::string spirv = R"(
- OpCapability Geometry
- OpMemoryModel Logical GLSL450
- OpEntryPoint Geometry %main "main"
- OpExecutionMode %main OutputPoints
- )" + kVoidFunction;
- CompileSuccessfully(spirv);
- EXPECT_THAT(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(
- getDiagnosticString(),
- HasSubstr("Geometry execution model entry points must specify exactly "
- "one of InputPoints, InputLines, InputLinesAdjacency, "
- "Triangles or InputTrianglesAdjacency execution modes."));
- }
- TEST_F(ValidateMode, FragmentNoOrigin) {
- const std::string spirv = R"(
- OpCapability Shader
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %main "main"
- )" + kVoidFunction;
- CompileSuccessfully(spirv);
- EXPECT_THAT(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(
- getDiagnosticString(),
- HasSubstr("Fragment execution model entry points require either an "
- "OriginUpperLeft or OriginLowerLeft execution mode."));
- }
- TEST_F(ValidateMode, FragmentBothOrigins) {
- const std::string spirv = R"(
- OpCapability Shader
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %main "main"
- OpExecutionMode %main OriginUpperLeft
- OpExecutionMode %main OriginLowerLeft
- )" + kVoidFunction;
- CompileSuccessfully(spirv);
- EXPECT_THAT(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(
- getDiagnosticString(),
- HasSubstr("Fragment execution model entry points can only specify one of "
- "OriginUpperLeft or OriginLowerLeft execution modes."));
- }
- TEST_F(ValidateMode, FragmentDepthGreaterAndLess) {
- const std::string spirv = R"(
- OpCapability Shader
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %main "main"
- OpExecutionMode %main OriginUpperLeft
- OpExecutionMode %main DepthGreater
- OpExecutionMode %main DepthLess
- )" + kVoidFunction;
- CompileSuccessfully(spirv);
- EXPECT_THAT(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Fragment execution model entry points can specify at "
- "most one of DepthGreater, DepthLess or DepthUnchanged "
- "execution modes."));
- }
- TEST_F(ValidateMode, FragmentDepthGreaterAndUnchanged) {
- const std::string spirv = R"(
- OpCapability Shader
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %main "main"
- OpExecutionMode %main OriginUpperLeft
- OpExecutionMode %main DepthGreater
- OpExecutionMode %main DepthUnchanged
- )" + kVoidFunction;
- CompileSuccessfully(spirv);
- EXPECT_THAT(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Fragment execution model entry points can specify at "
- "most one of DepthGreater, DepthLess or DepthUnchanged "
- "execution modes."));
- }
- TEST_F(ValidateMode, FragmentDepthLessAndUnchanged) {
- const std::string spirv = R"(
- OpCapability Shader
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %main "main"
- OpExecutionMode %main OriginUpperLeft
- OpExecutionMode %main DepthLess
- OpExecutionMode %main DepthUnchanged
- )" + kVoidFunction;
- CompileSuccessfully(spirv);
- EXPECT_THAT(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Fragment execution model entry points can specify at "
- "most one of DepthGreater, DepthLess or DepthUnchanged "
- "execution modes."));
- }
- TEST_F(ValidateMode, FragmentAllDepths) {
- const std::string spirv = R"(
- OpCapability Shader
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %main "main"
- OpExecutionMode %main OriginUpperLeft
- OpExecutionMode %main DepthGreater
- OpExecutionMode %main DepthLess
- OpExecutionMode %main DepthUnchanged
- )" + kVoidFunction;
- CompileSuccessfully(spirv);
- EXPECT_THAT(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Fragment execution model entry points can specify at "
- "most one of DepthGreater, DepthLess or DepthUnchanged "
- "execution modes."));
- }
- TEST_F(ValidateMode, TessellationControlSpacingEqualAndFractionalOdd) {
- const std::string spirv = R"(
- OpCapability Tessellation
- OpMemoryModel Logical GLSL450
- OpEntryPoint TessellationControl %main "main"
- OpExecutionMode %main SpacingEqual
- OpExecutionMode %main SpacingFractionalOdd
- )" + kVoidFunction;
- CompileSuccessfully(spirv);
- EXPECT_THAT(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Tessellation execution model entry points can specify "
- "at most one of SpacingEqual, SpacingFractionalOdd or "
- "SpacingFractionalEven execution modes."));
- }
- TEST_F(ValidateMode, TessellationControlSpacingEqualAndSpacingFractionalEven) {
- const std::string spirv = R"(
- OpCapability Tessellation
- OpMemoryModel Logical GLSL450
- OpEntryPoint TessellationControl %main "main"
- OpExecutionMode %main SpacingEqual
- OpExecutionMode %main SpacingFractionalEven
- )" + kVoidFunction;
- CompileSuccessfully(spirv);
- EXPECT_THAT(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Tessellation execution model entry points can specify "
- "at most one of SpacingEqual, SpacingFractionalOdd or "
- "SpacingFractionalEven execution modes."));
- }
- TEST_F(ValidateMode,
- TessellationControlSpacingFractionalOddAndSpacingFractionalEven) {
- const std::string spirv = R"(
- OpCapability Tessellation
- OpMemoryModel Logical GLSL450
- OpEntryPoint TessellationControl %main "main"
- OpExecutionMode %main SpacingFractionalOdd
- OpExecutionMode %main SpacingFractionalEven
- )" + kVoidFunction;
- CompileSuccessfully(spirv);
- EXPECT_THAT(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Tessellation execution model entry points can specify "
- "at most one of SpacingEqual, SpacingFractionalOdd or "
- "SpacingFractionalEven execution modes."));
- }
- TEST_F(ValidateMode, TessellationControlAllSpacing) {
- const std::string spirv = R"(
- OpCapability Tessellation
- OpMemoryModel Logical GLSL450
- OpEntryPoint TessellationControl %main "main"
- OpExecutionMode %main SpacingEqual
- OpExecutionMode %main SpacingFractionalOdd
- OpExecutionMode %main SpacingFractionalEven
- )" + kVoidFunction;
- CompileSuccessfully(spirv);
- EXPECT_THAT(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Tessellation execution model entry points can specify "
- "at most one of SpacingEqual, SpacingFractionalOdd or "
- "SpacingFractionalEven execution modes."));
- }
- TEST_F(ValidateMode,
- TessellationEvaluationSpacingEqualAndSpacingFractionalOdd) {
- const std::string spirv = R"(
- OpCapability Tessellation
- OpMemoryModel Logical GLSL450
- OpEntryPoint TessellationEvaluation %main "main"
- OpExecutionMode %main SpacingEqual
- OpExecutionMode %main SpacingFractionalOdd
- )" + kVoidFunction;
- CompileSuccessfully(spirv);
- EXPECT_THAT(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Tessellation execution model entry points can specify "
- "at most one of SpacingEqual, SpacingFractionalOdd or "
- "SpacingFractionalEven execution modes."));
- }
- TEST_F(ValidateMode,
- TessellationEvaluationSpacingEqualAndSpacingFractionalEven) {
- const std::string spirv = R"(
- OpCapability Tessellation
- OpMemoryModel Logical GLSL450
- OpEntryPoint TessellationEvaluation %main "main"
- OpExecutionMode %main SpacingEqual
- OpExecutionMode %main SpacingFractionalEven
- )" + kVoidFunction;
- CompileSuccessfully(spirv);
- EXPECT_THAT(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Tessellation execution model entry points can specify "
- "at most one of SpacingEqual, SpacingFractionalOdd or "
- "SpacingFractionalEven execution modes."));
- }
- TEST_F(ValidateMode,
- TessellationEvaluationSpacingFractionalOddAndSpacingFractionalEven) {
- const std::string spirv = R"(
- OpCapability Tessellation
- OpMemoryModel Logical GLSL450
- OpEntryPoint TessellationEvaluation %main "main"
- OpExecutionMode %main SpacingFractionalOdd
- OpExecutionMode %main SpacingFractionalEven
- )" + kVoidFunction;
- CompileSuccessfully(spirv);
- EXPECT_THAT(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Tessellation execution model entry points can specify "
- "at most one of SpacingEqual, SpacingFractionalOdd or "
- "SpacingFractionalEven execution modes."));
- }
- TEST_F(ValidateMode, TessellationEvaluationAllSpacing) {
- const std::string spirv = R"(
- OpCapability Tessellation
- OpMemoryModel Logical GLSL450
- OpEntryPoint TessellationEvaluation %main "main"
- OpExecutionMode %main SpacingEqual
- OpExecutionMode %main SpacingFractionalOdd
- OpExecutionMode %main SpacingFractionalEven
- )" + kVoidFunction;
- CompileSuccessfully(spirv);
- EXPECT_THAT(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Tessellation execution model entry points can specify "
- "at most one of SpacingEqual, SpacingFractionalOdd or "
- "SpacingFractionalEven execution modes."));
- }
- TEST_F(ValidateMode, TessellationControlBothVertex) {
- const std::string spirv = R"(
- OpCapability Tessellation
- OpMemoryModel Logical GLSL450
- OpEntryPoint TessellationControl %main "main"
- OpExecutionMode %main VertexOrderCw
- OpExecutionMode %main VertexOrderCcw
- )" + kVoidFunction;
- CompileSuccessfully(spirv);
- EXPECT_THAT(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(
- getDiagnosticString(),
- HasSubstr("Tessellation execution model entry points can specify at most "
- "one of VertexOrderCw or VertexOrderCcw execution modes."));
- }
- TEST_F(ValidateMode, TessellationEvaluationBothVertex) {
- const std::string spirv = R"(
- OpCapability Tessellation
- OpMemoryModel Logical GLSL450
- OpEntryPoint TessellationEvaluation %main "main"
- OpExecutionMode %main VertexOrderCw
- OpExecutionMode %main VertexOrderCcw
- )" + kVoidFunction;
- CompileSuccessfully(spirv);
- EXPECT_THAT(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(
- getDiagnosticString(),
- HasSubstr("Tessellation execution model entry points can specify at most "
- "one of VertexOrderCw or VertexOrderCcw execution modes."));
- }
- using ValidateModeGeometry = spvtest::ValidateBase<std::tuple<
- std::tuple<std::string, std::string, std::string, std::string, std::string>,
- std::tuple<std::string, std::string, std::string>>>;
- TEST_P(ValidateModeGeometry, ExecutionMode) {
- std::vector<std::string> input_modes;
- std::vector<std::string> output_modes;
- input_modes.push_back(std::get<0>(std::get<0>(GetParam())));
- input_modes.push_back(std::get<1>(std::get<0>(GetParam())));
- input_modes.push_back(std::get<2>(std::get<0>(GetParam())));
- input_modes.push_back(std::get<3>(std::get<0>(GetParam())));
- input_modes.push_back(std::get<4>(std::get<0>(GetParam())));
- output_modes.push_back(std::get<0>(std::get<1>(GetParam())));
- output_modes.push_back(std::get<1>(std::get<1>(GetParam())));
- output_modes.push_back(std::get<2>(std::get<1>(GetParam())));
- std::ostringstream sstr;
- sstr << "OpCapability Geometry\n";
- sstr << "OpMemoryModel Logical GLSL450\n";
- sstr << "OpEntryPoint Geometry %main \"main\"\n";
- size_t num_input_modes = 0;
- for (auto input : input_modes) {
- if (!input.empty()) {
- num_input_modes++;
- sstr << "OpExecutionMode %main " << input << "\n";
- }
- }
- size_t num_output_modes = 0;
- for (auto output : output_modes) {
- if (!output.empty()) {
- num_output_modes++;
- sstr << "OpExecutionMode %main " << output << "\n";
- }
- }
- sstr << "%void = OpTypeVoid\n";
- sstr << "%void_fn = OpTypeFunction %void\n";
- sstr << "%int = OpTypeInt 32 0\n";
- sstr << "%int1 = OpConstant %int 1\n";
- sstr << "%main = OpFunction %void None %void_fn\n";
- sstr << "%entry = OpLabel\n";
- sstr << "OpReturn\n";
- sstr << "OpFunctionEnd\n";
- CompileSuccessfully(sstr.str());
- if (num_input_modes == 1 && num_output_modes == 1) {
- EXPECT_THAT(SPV_SUCCESS, ValidateInstructions());
- } else {
- EXPECT_THAT(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- if (num_input_modes != 1) {
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Geometry execution model entry points must "
- "specify exactly one of InputPoints, InputLines, "
- "InputLinesAdjacency, Triangles or "
- "InputTrianglesAdjacency execution modes."));
- } else {
- EXPECT_THAT(
- getDiagnosticString(),
- HasSubstr("Geometry execution model entry points must specify "
- "exactly one of OutputPoints, OutputLineStrip or "
- "OutputTriangleStrip execution modes."));
- }
- }
- }
- INSTANTIATE_TEST_SUITE_P(
- GeometryRequiredModes, ValidateModeGeometry,
- Combine(Combine(Values("InputPoints", ""), Values("InputLines", ""),
- Values("InputLinesAdjacency", ""), Values("Triangles", ""),
- Values("InputTrianglesAdjacency", "")),
- Combine(Values("OutputPoints", ""), Values("OutputLineStrip", ""),
- Values("OutputTriangleStrip", ""))));
- using ValidateModeExecution =
- spvtest::ValidateBase<std::tuple<spv_result_t, std::string, std::string,
- std::string, spv_target_env>>;
- TEST_P(ValidateModeExecution, ExecutionMode) {
- const spv_result_t expectation = std::get<0>(GetParam());
- const std::string error = std::get<1>(GetParam());
- const std::string model = std::get<2>(GetParam());
- const std::string mode = std::get<3>(GetParam());
- const spv_target_env env = std::get<4>(GetParam());
- std::ostringstream sstr;
- sstr << "OpCapability Shader\n";
- sstr << "OpCapability Geometry\n";
- sstr << "OpCapability Tessellation\n";
- sstr << "OpCapability TransformFeedback\n";
- if (!spvIsVulkanEnv(env)) {
- sstr << "OpCapability Kernel\n";
- if (env == SPV_ENV_UNIVERSAL_1_3) {
- sstr << "OpCapability SubgroupDispatch\n";
- }
- }
- sstr << "OpMemoryModel Logical GLSL450\n";
- sstr << "OpEntryPoint " << model << " %main \"main\"\n";
- if (mode.find("LocalSizeId") == 0 || mode.find("LocalSizeHintId") == 0 ||
- mode.find("SubgroupsPerWorkgroupId") == 0) {
- sstr << "OpExecutionModeId %main " << mode << "\n";
- } else {
- sstr << "OpExecutionMode %main " << mode << "\n";
- }
- if (model == "Geometry") {
- if (!(mode.find("InputPoints") == 0 || mode.find("InputLines") == 0 ||
- mode.find("InputLinesAdjacency") == 0 ||
- mode.find("Triangles") == 0 ||
- mode.find("InputTrianglesAdjacency") == 0)) {
- // Exactly one of the above modes is required for Geometry shaders.
- sstr << "OpExecutionMode %main InputPoints\n";
- }
- if (!(mode.find("OutputPoints") == 0 || mode.find("OutputLineStrip") == 0 ||
- mode.find("OutputTriangleStrip") == 0)) {
- // Exactly one of the above modes is required for Geometry shaders.
- sstr << "OpExecutionMode %main OutputPoints\n";
- }
- } else if (model == "Fragment") {
- if (!(mode.find("OriginUpperLeft") == 0 ||
- mode.find("OriginLowerLeft") == 0)) {
- // Exactly one of the above modes is required for Fragment shaders.
- sstr << "OpExecutionMode %main OriginUpperLeft\n";
- }
- }
- sstr << "%void = OpTypeVoid\n";
- sstr << "%void_fn = OpTypeFunction %void\n";
- sstr << "%int = OpTypeInt 32 0\n";
- sstr << "%int1 = OpConstant %int 1\n";
- sstr << "%main = OpFunction %void None %void_fn\n";
- sstr << "%entry = OpLabel\n";
- sstr << "OpReturn\n";
- sstr << "OpFunctionEnd\n";
- CompileSuccessfully(sstr.str(), env);
- EXPECT_THAT(expectation, ValidateInstructions(env));
- if (expectation != SPV_SUCCESS) {
- EXPECT_THAT(getDiagnosticString(), HasSubstr(error));
- }
- }
- INSTANTIATE_TEST_SUITE_P(
- ValidateModeGeometryOnlyGoodSpv10, ValidateModeExecution,
- Combine(Values(SPV_SUCCESS), Values(""), Values("Geometry"),
- Values("Invocations 3", "InputPoints", "InputLines",
- "InputLinesAdjacency", "InputTrianglesAdjacency",
- "OutputPoints", "OutputLineStrip", "OutputTriangleStrip"),
- Values(SPV_ENV_UNIVERSAL_1_0)));
- INSTANTIATE_TEST_SUITE_P(
- ValidateModeGeometryOnlyBadSpv10, ValidateModeExecution,
- Combine(Values(SPV_ERROR_INVALID_DATA),
- Values("Execution mode can only be used with the Geometry "
- "execution model."),
- Values("Fragment", "TessellationEvaluation", "TessellationControl",
- "GLCompute", "Vertex", "Kernel"),
- Values("Invocations 3", "InputPoints", "InputLines",
- "InputLinesAdjacency", "InputTrianglesAdjacency",
- "OutputPoints", "OutputLineStrip", "OutputTriangleStrip"),
- Values(SPV_ENV_UNIVERSAL_1_0)));
- INSTANTIATE_TEST_SUITE_P(
- ValidateModeTessellationOnlyGoodSpv10, ValidateModeExecution,
- Combine(Values(SPV_SUCCESS), Values(""),
- Values("TessellationControl", "TessellationEvaluation"),
- Values("SpacingEqual", "SpacingFractionalEven",
- "SpacingFractionalOdd", "VertexOrderCw", "VertexOrderCcw",
- "PointMode", "Quads", "Isolines"),
- Values(SPV_ENV_UNIVERSAL_1_0)));
- INSTANTIATE_TEST_SUITE_P(
- ValidateModeTessellationOnlyBadSpv10, ValidateModeExecution,
- Combine(Values(SPV_ERROR_INVALID_DATA),
- Values("Execution mode can only be used with a tessellation "
- "execution model."),
- Values("Fragment", "Geometry", "GLCompute", "Vertex", "Kernel"),
- Values("SpacingEqual", "SpacingFractionalEven",
- "SpacingFractionalOdd", "VertexOrderCw", "VertexOrderCcw",
- "PointMode", "Quads", "Isolines"),
- Values(SPV_ENV_UNIVERSAL_1_0)));
- INSTANTIATE_TEST_SUITE_P(ValidateModeGeometryAndTessellationGoodSpv10,
- ValidateModeExecution,
- Combine(Values(SPV_SUCCESS), Values(""),
- Values("TessellationControl",
- "TessellationEvaluation", "Geometry"),
- Values("Triangles", "OutputVertices 3"),
- Values(SPV_ENV_UNIVERSAL_1_0)));
- INSTANTIATE_TEST_SUITE_P(
- ValidateModeGeometryAndTessellationBadSpv10, ValidateModeExecution,
- Combine(Values(SPV_ERROR_INVALID_DATA),
- Values("Execution mode can only be used with a Geometry or "
- "tessellation execution model."),
- Values("Fragment", "GLCompute", "Vertex", "Kernel"),
- Values("Triangles", "OutputVertices 3"),
- Values(SPV_ENV_UNIVERSAL_1_0)));
- INSTANTIATE_TEST_SUITE_P(
- ValidateModeFragmentOnlyGoodSpv10, ValidateModeExecution,
- Combine(Values(SPV_SUCCESS), Values(""), Values("Fragment"),
- Values("PixelCenterInteger", "OriginUpperLeft", "OriginLowerLeft",
- "EarlyFragmentTests", "DepthReplacing", "DepthLess",
- "DepthUnchanged"),
- Values(SPV_ENV_UNIVERSAL_1_0)));
- INSTANTIATE_TEST_SUITE_P(
- ValidateModeFragmentOnlyBadSpv10, ValidateModeExecution,
- Combine(Values(SPV_ERROR_INVALID_DATA),
- Values("Execution mode can only be used with the Fragment "
- "execution model."),
- Values("Geometry", "TessellationControl", "TessellationEvaluation",
- "GLCompute", "Vertex", "Kernel"),
- Values("PixelCenterInteger", "OriginUpperLeft", "OriginLowerLeft",
- "EarlyFragmentTests", "DepthReplacing", "DepthGreater",
- "DepthLess", "DepthUnchanged"),
- Values(SPV_ENV_UNIVERSAL_1_0)));
- INSTANTIATE_TEST_SUITE_P(ValidateModeKernelOnlyGoodSpv13, ValidateModeExecution,
- Combine(Values(SPV_SUCCESS), Values(""),
- Values("Kernel"),
- Values("LocalSizeHint 1 1 1", "VecTypeHint 4",
- "ContractionOff",
- "LocalSizeHintId %int1 %int1 %int1"),
- Values(SPV_ENV_UNIVERSAL_1_3)));
- INSTANTIATE_TEST_SUITE_P(
- ValidateModeKernelOnlyBadSpv13, ValidateModeExecution,
- Combine(
- Values(SPV_ERROR_INVALID_DATA),
- Values(
- "Execution mode can only be used with the Kernel execution model."),
- Values("Geometry", "TessellationControl", "TessellationEvaluation",
- "GLCompute", "Vertex", "Fragment"),
- Values("LocalSizeHint 1 1 1", "VecTypeHint 4", "ContractionOff",
- "LocalSizeHintId %int1 %int1 %int1"),
- Values(SPV_ENV_UNIVERSAL_1_3)));
- INSTANTIATE_TEST_SUITE_P(
- ValidateModeGLComputeAndKernelGoodSpv13, ValidateModeExecution,
- Combine(Values(SPV_SUCCESS), Values(""), Values("Kernel", "GLCompute"),
- Values("LocalSize 1 1 1", "LocalSizeId %int1 %int1 %int1"),
- Values(SPV_ENV_UNIVERSAL_1_3)));
- INSTANTIATE_TEST_SUITE_P(
- ValidateModeGLComputeAndKernelBadSpv13, ValidateModeExecution,
- Combine(Values(SPV_ERROR_INVALID_DATA),
- Values("Execution mode can only be used with a Kernel or GLCompute "
- "execution model."),
- Values("Geometry", "TessellationControl", "TessellationEvaluation",
- "Fragment", "Vertex"),
- Values("LocalSize 1 1 1", "LocalSizeId %int1 %int1 %int1"),
- Values(SPV_ENV_UNIVERSAL_1_3)));
- INSTANTIATE_TEST_SUITE_P(
- ValidateModeAllGoodSpv13, ValidateModeExecution,
- Combine(Values(SPV_SUCCESS), Values(""),
- Values("Kernel", "GLCompute", "Geometry", "TessellationControl",
- "TessellationEvaluation", "Fragment", "Vertex"),
- Values("Xfb", "Initializer", "Finalizer", "SubgroupSize 1",
- "SubgroupsPerWorkgroup 1", "SubgroupsPerWorkgroupId %int1"),
- Values(SPV_ENV_UNIVERSAL_1_3)));
- TEST_F(ValidateModeExecution, MeshNVLocalSize) {
- const std::string spirv = R"(
- OpCapability Shader
- OpCapability MeshShadingNV
- OpExtension "SPV_NV_mesh_shader"
- OpMemoryModel Logical GLSL450
- OpEntryPoint MeshNV %main "main"
- OpExecutionMode %main LocalSize 1 1 1
- )" + kVoidFunction;
- CompileSuccessfully(spirv);
- EXPECT_THAT(SPV_SUCCESS, ValidateInstructions());
- }
- TEST_F(ValidateModeExecution, TaskNVLocalSize) {
- const std::string spirv = R"(
- OpCapability Shader
- OpCapability MeshShadingNV
- OpExtension "SPV_NV_mesh_shader"
- OpMemoryModel Logical GLSL450
- OpEntryPoint TaskNV %main "main"
- OpExecutionMode %main LocalSize 1 1 1
- )" + kVoidFunction;
- CompileSuccessfully(spirv);
- EXPECT_THAT(SPV_SUCCESS, ValidateInstructions());
- }
- TEST_F(ValidateModeExecution, MeshNVOutputPoints) {
- const std::string spirv = R"(
- OpCapability Shader
- OpCapability MeshShadingNV
- OpExtension "SPV_NV_mesh_shader"
- OpMemoryModel Logical GLSL450
- OpEntryPoint MeshNV %main "main"
- OpExecutionMode %main OutputPoints
- )" + kVoidFunction;
- CompileSuccessfully(spirv);
- EXPECT_THAT(SPV_SUCCESS, ValidateInstructions());
- }
- TEST_F(ValidateModeExecution, MeshNVOutputVertices) {
- const std::string spirv = R"(
- OpCapability Shader
- OpCapability MeshShadingNV
- OpExtension "SPV_NV_mesh_shader"
- OpMemoryModel Logical GLSL450
- OpEntryPoint MeshNV %main "main"
- OpExecutionMode %main OutputVertices 42
- )" + kVoidFunction;
- CompileSuccessfully(spirv);
- EXPECT_THAT(SPV_SUCCESS, ValidateInstructions());
- }
- TEST_F(ValidateModeExecution, MeshNVLocalSizeId) {
- const std::string spirv = R"(
- OpCapability Shader
- OpCapability MeshShadingNV
- OpExtension "SPV_NV_mesh_shader"
- OpMemoryModel Logical GLSL450
- OpEntryPoint MeshNV %main "main"
- OpExecutionModeId %main LocalSizeId %int_1 %int_1 %int_1
- %int = OpTypeInt 32 0
- %int_1 = OpConstant %int 1
- )" + kVoidFunction;
- spv_target_env env = SPV_ENV_UNIVERSAL_1_3;
- CompileSuccessfully(spirv, env);
- EXPECT_THAT(SPV_SUCCESS, ValidateInstructions(env));
- }
- TEST_F(ValidateModeExecution, TaskNVLocalSizeId) {
- const std::string spirv = R"(
- OpCapability Shader
- OpCapability MeshShadingNV
- OpExtension "SPV_NV_mesh_shader"
- OpMemoryModel Logical GLSL450
- OpEntryPoint TaskNV %main "main"
- OpExecutionModeId %main LocalSizeId %int_1 %int_1 %int_1
- %int = OpTypeInt 32 0
- %int_1 = OpConstant %int 1
- )" + kVoidFunction;
- spv_target_env env = SPV_ENV_UNIVERSAL_1_3;
- CompileSuccessfully(spirv, env);
- EXPECT_THAT(SPV_SUCCESS, ValidateInstructions(env));
- }
- TEST_F(ValidateModeExecution, ExecModeSubgroupsPerWorkgroupIdBad) {
- const std::string spirv = R"(
- OpCapability Shader
- OpCapability SubgroupDispatch
- OpMemoryModel Logical GLSL450
- OpEntryPoint Vertex %main "main"
- OpExecutionMode %main SubgroupsPerWorkgroupId %int_1
- %int = OpTypeInt 32 0
- %int_1 = OpConstant %int 1
- )" + kVoidFunction;
- spv_target_env env = SPV_ENV_UNIVERSAL_1_3;
- CompileSuccessfully(spirv, env);
- EXPECT_THAT(SPV_ERROR_INVALID_DATA, ValidateInstructions(env));
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("OpExecutionMode is only valid when the Mode operand "
- "is an execution mode that takes no Extra Operands"));
- }
- TEST_F(ValidateModeExecution, ExecModeIdSubgroupsPerWorkgroupIdGood) {
- const std::string spirv = R"(
- OpCapability Shader
- OpCapability SubgroupDispatch
- OpMemoryModel Logical GLSL450
- OpEntryPoint Vertex %main "main"
- OpExecutionModeId %main SubgroupsPerWorkgroupId %int_1
- %int = OpTypeInt 32 0
- %int_1 = OpConstant %int 1
- )" + kVoidFunction;
- spv_target_env env = SPV_ENV_UNIVERSAL_1_3;
- CompileSuccessfully(spirv, env);
- EXPECT_THAT(SPV_SUCCESS, ValidateInstructions(env));
- }
- TEST_F(ValidateModeExecution, ExecModeIdSubgroupsPerWorkgroupIdNonConstantBad) {
- const std::string spirv = R"(
- OpCapability Shader
- OpCapability SubgroupDispatch
- OpMemoryModel Logical GLSL450
- OpEntryPoint Vertex %main "main"
- OpExecutionModeId %main SubgroupsPerWorkgroupId %int_1
- %int = OpTypeInt 32 0
- %int_ptr = OpTypePointer Private %int
- %int_1 = OpVariable %int_ptr Private
- )" + kVoidFunction;
- spv_target_env env = SPV_ENV_UNIVERSAL_1_3;
- CompileSuccessfully(spirv, env);
- EXPECT_THAT(SPV_ERROR_INVALID_ID, ValidateInstructions(env));
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("For OpExecutionModeId all Extra Operand ids must be "
- "constant instructions."));
- }
- TEST_F(ValidateModeExecution, ExecModeLocalSizeHintIdBad) {
- const std::string spirv = R"(
- OpCapability Kernel
- OpCapability Shader
- OpMemoryModel Logical GLSL450
- OpEntryPoint Kernel %main "main"
- OpExecutionMode %main LocalSizeHintId %int_1 %int_1 %int_1
- %int = OpTypeInt 32 0
- %int_1 = OpConstant %int 1
- )" + kVoidFunction;
- spv_target_env env = SPV_ENV_UNIVERSAL_1_3;
- CompileSuccessfully(spirv, env);
- EXPECT_THAT(SPV_ERROR_INVALID_DATA, ValidateInstructions(env));
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("OpExecutionMode is only valid when the Mode operand "
- "is an execution mode that takes no Extra Operands"));
- }
- TEST_F(ValidateModeExecution, ExecModeIdLocalSizeHintIdGood) {
- const std::string spirv = R"(
- OpCapability Kernel
- OpCapability Shader
- OpMemoryModel Logical GLSL450
- OpEntryPoint Kernel %main "main"
- OpExecutionModeId %main LocalSizeHintId %int_1 %int_1 %int_1
- %int = OpTypeInt 32 0
- %int_1 = OpConstant %int 1
- )" + kVoidFunction;
- spv_target_env env = SPV_ENV_UNIVERSAL_1_3;
- CompileSuccessfully(spirv, env);
- EXPECT_THAT(SPV_SUCCESS, ValidateInstructions(env));
- }
- TEST_F(ValidateModeExecution, ExecModeIdLocalSizeHintIdNonConstantBad) {
- const std::string spirv = R"(
- OpCapability Kernel
- OpCapability Shader
- OpMemoryModel Logical GLSL450
- OpEntryPoint Vertex %main "main"
- OpExecutionModeId %main LocalSizeHintId %int_1 %int_1 %int_1
- %int = OpTypeInt 32 0
- %int_ptr = OpTypePointer Private %int
- %int_1 = OpVariable %int_ptr Private
- )" + kVoidFunction;
- spv_target_env env = SPV_ENV_UNIVERSAL_1_3;
- CompileSuccessfully(spirv, env);
- EXPECT_THAT(SPV_ERROR_INVALID_ID, ValidateInstructions(env));
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("For OpExecutionModeId all Extra Operand ids must be "
- "constant instructions."));
- }
- TEST_F(ValidateModeExecution, ExecModeLocalSizeIdBad) {
- const std::string spirv = R"(
- OpCapability Kernel
- OpCapability Shader
- OpMemoryModel Logical GLSL450
- OpEntryPoint Kernel %main "main"
- OpExecutionMode %main LocalSizeId %int_1 %int_1 %int_1
- %int = OpTypeInt 32 0
- %int_1 = OpConstant %int 1
- )" + kVoidFunction;
- spv_target_env env = SPV_ENV_UNIVERSAL_1_3;
- CompileSuccessfully(spirv, env);
- EXPECT_THAT(SPV_ERROR_INVALID_DATA, ValidateInstructions(env));
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("OpExecutionMode is only valid when the Mode operand "
- "is an execution mode that takes no Extra Operands"));
- }
- TEST_F(ValidateModeExecution, ExecModeIdLocalSizeIdGood) {
- const std::string spirv = R"(
- OpCapability Kernel
- OpCapability Shader
- OpMemoryModel Logical GLSL450
- OpEntryPoint Kernel %main "main"
- OpExecutionModeId %main LocalSizeId %int_1 %int_1 %int_1
- %int = OpTypeInt 32 0
- %int_1 = OpConstant %int 1
- )" + kVoidFunction;
- spv_target_env env = SPV_ENV_UNIVERSAL_1_3;
- CompileSuccessfully(spirv, env);
- EXPECT_THAT(SPV_SUCCESS, ValidateInstructions(env));
- }
- TEST_F(ValidateModeExecution, ExecModeIdLocalSizeIdNonConstantBad) {
- const std::string spirv = R"(
- OpCapability Kernel
- OpCapability Shader
- OpMemoryModel Logical GLSL450
- OpEntryPoint Vertex %main "main"
- OpExecutionModeId %main LocalSizeId %int_1 %int_1 %int_1
- %int = OpTypeInt 32 0
- %int_ptr = OpTypePointer Private %int
- %int_1 = OpVariable %int_ptr Private
- )" + kVoidFunction;
- spv_target_env env = SPV_ENV_UNIVERSAL_1_3;
- CompileSuccessfully(spirv, env);
- EXPECT_THAT(SPV_ERROR_INVALID_ID, ValidateInstructions(env));
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("For OpExecutionModeId all Extra Operand ids must be "
- "constant instructions."));
- }
- TEST_F(ValidateMode, FragmentShaderInterlockVertexBad) {
- const std::string spirv = R"(
- OpCapability Shader
- OpCapability FragmentShaderPixelInterlockEXT
- OpExtension "SPV_EXT_fragment_shader_interlock"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Vertex %main "main"
- OpExecutionMode %main PixelInterlockOrderedEXT
- )" + kVoidFunction;
- CompileSuccessfully(spirv);
- EXPECT_THAT(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(
- getDiagnosticString(),
- HasSubstr(
- "Execution mode can only be used with the Fragment execution model"));
- }
- TEST_F(ValidateMode, FragmentShaderInterlockTooManyModesBad) {
- const std::string spirv = R"(
- OpCapability Shader
- OpCapability FragmentShaderPixelInterlockEXT
- OpCapability FragmentShaderSampleInterlockEXT
- OpExtension "SPV_EXT_fragment_shader_interlock"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %main "main"
- OpExecutionMode %main OriginUpperLeft
- OpExecutionMode %main PixelInterlockOrderedEXT
- OpExecutionMode %main SampleInterlockOrderedEXT
- )" + kVoidFunction;
- CompileSuccessfully(spirv);
- EXPECT_THAT(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(
- getDiagnosticString(),
- HasSubstr("Fragment execution model entry points can specify at most "
- "one fragment shader interlock execution mode"));
- }
- TEST_F(ValidateMode, FragmentShaderInterlockNoModeBad) {
- const std::string spirv = R"(
- OpCapability Shader
- OpCapability FragmentShaderPixelInterlockEXT
- OpExtension "SPV_EXT_fragment_shader_interlock"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %main "main"
- OpExecutionMode %main OriginUpperLeft
- %void = OpTypeVoid
- %void_fn = OpTypeFunction %void
- %func = OpFunction %void None %void_fn
- %entryf = OpLabel
- OpBeginInvocationInterlockEXT
- OpEndInvocationInterlockEXT
- OpReturn
- OpFunctionEnd
- %main = OpFunction %void None %void_fn
- %entry = OpLabel
- %1 = OpFunctionCall %void %func
- OpReturn
- OpFunctionEnd
- )";
- CompileSuccessfully(spirv);
- EXPECT_THAT(SPV_ERROR_INVALID_ID, ValidateInstructions());
- EXPECT_THAT(
- getDiagnosticString(),
- HasSubstr(
- "OpBeginInvocationInterlockEXT/OpEndInvocationInterlockEXT require a "
- "fragment shader interlock execution mode"));
- }
- TEST_F(ValidateMode, FragmentShaderInterlockGood) {
- const std::string spirv = R"(
- OpCapability Shader
- OpCapability FragmentShaderPixelInterlockEXT
- OpExtension "SPV_EXT_fragment_shader_interlock"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %main "main"
- OpExecutionMode %main OriginUpperLeft
- OpExecutionMode %main PixelInterlockOrderedEXT
- %void = OpTypeVoid
- %void_fn = OpTypeFunction %void
- %func = OpFunction %void None %void_fn
- %entryf = OpLabel
- OpBeginInvocationInterlockEXT
- OpEndInvocationInterlockEXT
- OpReturn
- OpFunctionEnd
- %main = OpFunction %void None %void_fn
- %entry = OpLabel
- %1 = OpFunctionCall %void %func
- OpReturn
- OpFunctionEnd
- )";
- CompileSuccessfully(spirv);
- EXPECT_THAT(SPV_SUCCESS, ValidateInstructions());
- }
- TEST_F(ValidateMode, FragmentShaderStencilRefFrontTooManyModesBad) {
- const std::string spirv = R"(
- OpCapability Shader
- OpCapability StencilExportEXT
- OpExtension "SPV_AMD_shader_early_and_late_fragment_tests"
- OpExtension "SPV_EXT_shader_stencil_export"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %main "main"
- OpExecutionMode %main OriginUpperLeft
- OpExecutionMode %main EarlyAndLateFragmentTestsAMD
- OpExecutionMode %main StencilRefLessFrontAMD
- OpExecutionMode %main StencilRefGreaterFrontAMD
- )" + kVoidFunction;
- CompileSuccessfully(spirv);
- EXPECT_THAT(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(
- getDiagnosticString(),
- HasSubstr("Fragment execution model entry points can specify at most "
- "one of StencilRefUnchangedFrontAMD, "
- "StencilRefLessFrontAMD or StencilRefGreaterFrontAMD "
- "execution modes."));
- }
- TEST_F(ValidateMode, FragmentShaderStencilRefBackTooManyModesBad) {
- const std::string spirv = R"(
- OpCapability Shader
- OpCapability StencilExportEXT
- OpExtension "SPV_AMD_shader_early_and_late_fragment_tests"
- OpExtension "SPV_EXT_shader_stencil_export"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %main "main"
- OpExecutionMode %main OriginUpperLeft
- OpExecutionMode %main EarlyAndLateFragmentTestsAMD
- OpExecutionMode %main StencilRefLessBackAMD
- OpExecutionMode %main StencilRefGreaterBackAMD
- )" + kVoidFunction;
- CompileSuccessfully(spirv);
- EXPECT_THAT(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(
- getDiagnosticString(),
- HasSubstr("Fragment execution model entry points can specify at most "
- "one of StencilRefUnchangedBackAMD, "
- "StencilRefLessBackAMD or StencilRefGreaterBackAMD "
- "execution modes."));
- }
- TEST_F(ValidateMode, FragmentShaderStencilRefFrontGood) {
- const std::string spirv = R"(
- OpCapability Shader
- OpCapability StencilExportEXT
- OpExtension "SPV_AMD_shader_early_and_late_fragment_tests"
- OpExtension "SPV_EXT_shader_stencil_export"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %main "main"
- OpExecutionMode %main OriginUpperLeft
- OpExecutionMode %main EarlyAndLateFragmentTestsAMD
- OpExecutionMode %main StencilRefLessFrontAMD
- )" + kVoidFunction;
- CompileSuccessfully(spirv);
- EXPECT_THAT(SPV_SUCCESS, ValidateInstructions());
- }
- TEST_F(ValidateMode, FragmentShaderStencilRefBackGood) {
- const std::string spirv = R"(
- OpCapability Shader
- OpCapability StencilExportEXT
- OpExtension "SPV_AMD_shader_early_and_late_fragment_tests"
- OpExtension "SPV_EXT_shader_stencil_export"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %main "main"
- OpExecutionMode %main OriginUpperLeft
- OpExecutionMode %main EarlyAndLateFragmentTestsAMD
- OpExecutionMode %main StencilRefLessBackAMD
- )" + kVoidFunction;
- CompileSuccessfully(spirv);
- EXPECT_THAT(SPV_SUCCESS, ValidateInstructions());
- }
- TEST_F(ValidateMode, FragmentShaderDemoteVertexBad) {
- const std::string spirv = R"(
- OpCapability Shader
- OpCapability DemoteToHelperInvocationEXT
- OpExtension "SPV_EXT_demote_to_helper_invocation"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Vertex %main "main"
- %bool = OpTypeBool
- %void = OpTypeVoid
- %void_fn = OpTypeFunction %void
- %main = OpFunction %void None %void_fn
- %entry = OpLabel
- OpDemoteToHelperInvocationEXT
- %1 = OpIsHelperInvocationEXT %bool
- OpReturn
- OpFunctionEnd
- )";
- CompileSuccessfully(spirv);
- EXPECT_THAT(SPV_ERROR_INVALID_ID, ValidateInstructions());
- EXPECT_THAT(
- getDiagnosticString(),
- HasSubstr(
- "OpDemoteToHelperInvocationEXT requires Fragment execution model"));
- EXPECT_THAT(
- getDiagnosticString(),
- HasSubstr("OpIsHelperInvocationEXT requires Fragment execution model"));
- }
- TEST_F(ValidateMode, FragmentShaderDemoteGood) {
- const std::string spirv = R"(
- OpCapability Shader
- OpCapability DemoteToHelperInvocationEXT
- OpExtension "SPV_EXT_demote_to_helper_invocation"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %main "main"
- OpExecutionMode %main OriginUpperLeft
- %bool = OpTypeBool
- %void = OpTypeVoid
- %void_fn = OpTypeFunction %void
- %main = OpFunction %void None %void_fn
- %entry = OpLabel
- OpDemoteToHelperInvocationEXT
- %1 = OpIsHelperInvocationEXT %bool
- OpReturn
- OpFunctionEnd
- )";
- CompileSuccessfully(spirv);
- EXPECT_THAT(SPV_SUCCESS, ValidateInstructions());
- }
- TEST_F(ValidateMode, FragmentShaderDemoteBadType) {
- const std::string spirv = R"(
- OpCapability Shader
- OpCapability DemoteToHelperInvocationEXT
- OpExtension "SPV_EXT_demote_to_helper_invocation"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %main "main"
- OpExecutionMode %main OriginUpperLeft
- %u32 = OpTypeInt 32 0
- %void = OpTypeVoid
- %void_fn = OpTypeFunction %void
- %main = OpFunction %void None %void_fn
- %entry = OpLabel
- OpDemoteToHelperInvocationEXT
- %1 = OpIsHelperInvocationEXT %u32
- OpReturn
- OpFunctionEnd
- )";
- CompileSuccessfully(spirv);
- EXPECT_THAT(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Expected bool scalar type as Result Type"));
- }
- TEST_F(ValidateMode, LocalSizeIdVulkan1p3DoesNotRequireOption) {
- const std::string spirv = R"(
- OpCapability Shader
- OpMemoryModel Logical GLSL450
- OpEntryPoint GLCompute %main "main"
- OpExecutionModeId %main LocalSizeId %int_1 %int_1 %int_1
- %void = OpTypeVoid
- %int = OpTypeInt 32 0
- %int_1 = OpConstant %int 1
- %void_fn = OpTypeFunction %void
- %main = OpFunction %void None %void_fn
- %entry = OpLabel
- OpReturn
- OpFunctionEnd
- )";
- CompileSuccessfully(spirv, SPV_ENV_VULKAN_1_3);
- EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_3));
- }
- } // namespace
- } // namespace val
- } // namespace spvtools
|