1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717 |
- // 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 "assembly_builder.h"
- #include "gmock/gmock.h"
- #include "pass_fixture.h"
- #include "pass_utils.h"
- namespace {
- using namespace spvtools;
- using UpgradeMemoryModelTest = opt::PassTest<::testing::Test>;
- TEST_F(UpgradeMemoryModelTest, InvalidMemoryModelOpenCL) {
- const std::string text = R"(
- ; CHECK: OpMemoryModel Logical OpenCL
- OpCapability Kernel
- OpCapability Linkage
- OpMemoryModel Logical OpenCL
- )";
- SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true);
- }
- TEST_F(UpgradeMemoryModelTest, InvalidMemoryModelVulkanKHR) {
- const std::string text = R"(
- ; CHECK: OpMemoryModel Logical VulkanKHR
- OpCapability Shader
- OpCapability Linkage
- OpCapability VulkanMemoryModelKHR
- OpExtension "SPV_KHR_vulkan_memory_model"
- OpMemoryModel Logical VulkanKHR
- )";
- SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true);
- }
- TEST_F(UpgradeMemoryModelTest, JustMemoryModel) {
- const std::string text = R"(
- ; CHECK: OpCapability VulkanMemoryModelKHR
- ; CHECK: OpExtension "SPV_KHR_vulkan_memory_model"
- ; CHECK: OpMemoryModel Logical VulkanKHR
- OpCapability Shader
- OpCapability Linkage
- OpMemoryModel Logical GLSL450
- )";
- SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true);
- }
- TEST_F(UpgradeMemoryModelTest, RemoveDecorations) {
- const std::string text = R"(
- ; CHECK-NOT: OpDecorate
- OpCapability Shader
- OpCapability Linkage
- OpMemoryModel Logical GLSL450
- OpDecorate %var Volatile
- OpDecorate %var Coherent
- %int = OpTypeInt 32 0
- %ptr_int_Uniform = OpTypePointer Uniform %int
- %var = OpVariable %ptr_int_Uniform Uniform
- )";
- SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true);
- }
- TEST_F(UpgradeMemoryModelTest, WorkgroupVariable) {
- const std::string text = R"(
- ; CHECK: [[scope:%\w+]] = OpConstant {{%\w+}} 2
- ; CHECK: OpLoad {{%\w+}} {{%\w+}} MakePointerVisibleKHR|NonPrivatePointerKHR [[scope]]
- ; CHECK: OpStore {{%\w+}} {{%\w+}} MakePointerAvailableKHR|NonPrivatePointerKHR [[scope]]
- OpCapability Shader
- OpCapability Linkage
- OpMemoryModel Logical GLSL450
- %void = OpTypeVoid
- %int = OpTypeInt 32 0
- %ptr_int_Workgroup = OpTypePointer Workgroup %int
- %var = OpVariable %ptr_int_Workgroup Workgroup
- %func_ty = OpTypeFunction %void
- %func = OpFunction %void None %func_ty
- %1 = OpLabel
- %ld = OpLoad %int %var
- %st = OpStore %var %ld
- OpReturn
- OpFunctionEnd
- )";
- SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true);
- }
- TEST_F(UpgradeMemoryModelTest, WorkgroupFunctionParameter) {
- const std::string text = R"(
- ; CHECK: [[scope:%\w+]] = OpConstant {{%\w+}} 2
- ; CHECK: OpLoad {{%\w+}} {{%\w+}} MakePointerVisibleKHR|NonPrivatePointerKHR [[scope]]
- ; CHECK: OpStore {{%\w+}} {{%\w+}} MakePointerAvailableKHR|NonPrivatePointerKHR [[scope]]
- OpCapability Shader
- OpCapability Linkage
- OpMemoryModel Logical GLSL450
- %void = OpTypeVoid
- %int = OpTypeInt 32 0
- %ptr_int_Workgroup = OpTypePointer Workgroup %int
- %func_ty = OpTypeFunction %void %ptr_int_Workgroup
- %func = OpFunction %void None %func_ty
- %param = OpFunctionParameter %ptr_int_Workgroup
- %1 = OpLabel
- %ld = OpLoad %int %param
- %st = OpStore %param %ld
- OpReturn
- OpFunctionEnd
- )";
- SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true);
- }
- TEST_F(UpgradeMemoryModelTest, SimpleUniformVariable) {
- const std::string text = R"(
- ; CHECK-NOT: OpDecorate
- ; CHECK: [[scope:%\w+]] = OpConstant {{%\w+}} 5
- ; CHECK: OpLoad {{%\w+}} {{%\w+}} Volatile|MakePointerVisibleKHR|NonPrivatePointerKHR [[scope]]
- ; CHECK: OpStore {{%\w+}} {{%\w+}} Volatile|MakePointerAvailableKHR|NonPrivatePointerKHR [[scope]]
- OpCapability Shader
- OpCapability Linkage
- OpMemoryModel Logical GLSL450
- OpDecorate %var Coherent
- OpDecorate %var Volatile
- %void = OpTypeVoid
- %int = OpTypeInt 32 0
- %ptr_int_Uniform = OpTypePointer Uniform %int
- %var = OpVariable %ptr_int_Uniform Uniform
- %func_ty = OpTypeFunction %void
- %func = OpFunction %void None %func_ty
- %1 = OpLabel
- %ld = OpLoad %int %var
- OpStore %var %ld
- OpReturn
- OpFunctionEnd
- )";
- SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true);
- }
- TEST_F(UpgradeMemoryModelTest, SimpleUniformFunctionParameter) {
- const std::string text = R"(
- ; CHECK-NOT: OpDecorate
- ; CHECK: [[scope:%\w+]] = OpConstant {{%\w+}} 5
- ; CHECK: OpLoad {{%\w+}} {{%\w+}} Volatile|MakePointerVisibleKHR|NonPrivatePointerKHR [[scope]]
- ; CHECK: OpStore {{%\w+}} {{%\w+}} Volatile|MakePointerAvailableKHR|NonPrivatePointerKHR [[scope]]
- OpCapability Shader
- OpCapability Linkage
- OpMemoryModel Logical GLSL450
- OpDecorate %param Coherent
- OpDecorate %param Volatile
- %void = OpTypeVoid
- %int = OpTypeInt 32 0
- %ptr_int_Uniform = OpTypePointer Uniform %int
- %func_ty = OpTypeFunction %void %ptr_int_Uniform
- %func = OpFunction %void None %func_ty
- %param = OpFunctionParameter %ptr_int_Uniform
- %1 = OpLabel
- %ld = OpLoad %int %param
- OpStore %param %ld
- OpReturn
- OpFunctionEnd
- )";
- SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true);
- }
- TEST_F(UpgradeMemoryModelTest, SimpleUniformVariableOnlyVolatile) {
- const std::string text = R"(
- ; CHECK-NOT: OpDecorate
- ; CHECK-NOT: OpConstant
- ; CHECK: OpLoad {{%\w+}} {{%\w+}} Volatile
- ; CHECK: OpStore {{%\w+}} {{%\w+}} Volatile
- OpCapability Shader
- OpCapability Linkage
- OpMemoryModel Logical GLSL450
- OpDecorate %var Volatile
- %void = OpTypeVoid
- %int = OpTypeInt 32 0
- %ptr_int_Uniform = OpTypePointer Uniform %int
- %var = OpVariable %ptr_int_Uniform Uniform
- %func_ty = OpTypeFunction %void
- %func = OpFunction %void None %func_ty
- %1 = OpLabel
- %ld = OpLoad %int %var
- OpStore %var %ld
- OpReturn
- OpFunctionEnd
- )";
- SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true);
- }
- TEST_F(UpgradeMemoryModelTest, SimpleUniformVariableCopied) {
- const std::string text = R"(
- ; CHECK-NOT: OpDecorate
- ; CHECK: [[scope:%\w+]] = OpConstant {{%\w+}} 5
- ; CHECK: OpLoad {{%\w+}} {{%\w+}} Volatile|MakePointerVisibleKHR|NonPrivatePointerKHR [[scope]]
- ; CHECK: OpStore {{%\w+}} {{%\w+}} Volatile|MakePointerAvailableKHR|NonPrivatePointerKHR [[scope]]
- OpCapability Shader
- OpCapability Linkage
- OpMemoryModel Logical GLSL450
- OpDecorate %var Coherent
- OpDecorate %var Volatile
- %void = OpTypeVoid
- %int = OpTypeInt 32 0
- %ptr_int_Uniform = OpTypePointer Uniform %int
- %var = OpVariable %ptr_int_Uniform Uniform
- %func_ty = OpTypeFunction %void
- %func = OpFunction %void None %func_ty
- %1 = OpLabel
- %copy = OpCopyObject %ptr_int_Uniform %var
- %ld = OpLoad %int %copy
- OpStore %copy %ld
- OpReturn
- OpFunctionEnd
- )";
- SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true);
- }
- TEST_F(UpgradeMemoryModelTest, SimpleUniformFunctionParameterCopied) {
- const std::string text = R"(
- ; CHECK-NOT: OpDecorate
- ; CHECK: [[scope:%\w+]] = OpConstant {{%\w+}} 5
- ; CHECK: OpLoad {{%\w+}} {{%\w+}} Volatile|MakePointerVisibleKHR|NonPrivatePointerKHR [[scope]]
- ; CHECK: OpStore {{%\w+}} {{%\w+}} Volatile|MakePointerAvailableKHR|NonPrivatePointerKHR [[scope]]
- OpCapability Shader
- OpCapability Linkage
- OpMemoryModel Logical GLSL450
- OpDecorate %param Coherent
- OpDecorate %param Volatile
- %void = OpTypeVoid
- %int = OpTypeInt 32 0
- %ptr_int_Uniform = OpTypePointer Uniform %int
- %func_ty = OpTypeFunction %void %ptr_int_Uniform
- %func = OpFunction %void None %func_ty
- %param = OpFunctionParameter %ptr_int_Uniform
- %1 = OpLabel
- %copy = OpCopyObject %ptr_int_Uniform %param
- %ld = OpLoad %int %copy
- %copy2 = OpCopyObject %ptr_int_Uniform %param
- OpStore %copy2 %ld
- OpReturn
- OpFunctionEnd
- )";
- SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true);
- }
- TEST_F(UpgradeMemoryModelTest, SimpleUniformVariableAccessChain) {
- const std::string text = R"(
- ; CHECK-NOT: OpDecorate
- ; CHECK: [[scope:%\w+]] = OpConstant {{%\w+}} 5
- ; CHECK: OpLoad {{%\w+}} {{%\w+}} Volatile|MakePointerVisibleKHR|NonPrivatePointerKHR [[scope]]
- ; CHECK: OpStore {{%\w+}} {{%\w+}} Volatile|MakePointerAvailableKHR|NonPrivatePointerKHR [[scope]]
- OpCapability Shader
- OpCapability Linkage
- OpMemoryModel Logical GLSL450
- OpDecorate %var Coherent
- OpDecorate %var Volatile
- %void = OpTypeVoid
- %int = OpTypeInt 32 0
- %int0 = OpConstant %int 0
- %int3 = OpConstant %int 3
- %int_array_3 = OpTypeArray %int %int3
- %ptr_intarray_Uniform = OpTypePointer Uniform %int_array_3
- %ptr_int_Uniform = OpTypePointer Uniform %int
- %var = OpVariable %ptr_intarray_Uniform Uniform
- %func_ty = OpTypeFunction %void
- %func = OpFunction %void None %func_ty
- %1 = OpLabel
- %gep = OpAccessChain %ptr_int_Uniform %var %int0
- %ld = OpLoad %int %gep
- OpStore %gep %ld
- OpReturn
- OpFunctionEnd
- )";
- SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true);
- }
- TEST_F(UpgradeMemoryModelTest, SimpleUniformFunctionParameterAccessChain) {
- const std::string text = R"(
- ; CHECK-NOT: OpDecorate
- ; CHECK: [[scope:%\w+]] = OpConstant {{%\w+}} 5
- ; CHECK: OpLoad {{%\w+}} {{%\w+}} Volatile|MakePointerVisibleKHR|NonPrivatePointerKHR [[scope]]
- ; CHECK: OpStore {{%\w+}} {{%\w+}} Volatile|MakePointerAvailableKHR|NonPrivatePointerKHR [[scope]]
- OpCapability Shader
- OpCapability Linkage
- OpMemoryModel Logical GLSL450
- OpDecorate %param Coherent
- OpDecorate %param Volatile
- %void = OpTypeVoid
- %int = OpTypeInt 32 0
- %int0 = OpConstant %int 0
- %int3 = OpConstant %int 3
- %int_array_3 = OpTypeArray %int %int3
- %ptr_intarray_Uniform = OpTypePointer Uniform %int_array_3
- %ptr_int_Uniform = OpTypePointer Uniform %int
- %func_ty = OpTypeFunction %void %ptr_intarray_Uniform
- %func = OpFunction %void None %func_ty
- %param = OpFunctionParameter %ptr_intarray_Uniform
- %1 = OpLabel
- %ld_gep = OpAccessChain %ptr_int_Uniform %param %int0
- %ld = OpLoad %int %ld_gep
- %st_gep = OpAccessChain %ptr_int_Uniform %param %int0
- OpStore %st_gep %ld
- OpReturn
- OpFunctionEnd
- )";
- SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true);
- }
- TEST_F(UpgradeMemoryModelTest, VariablePointerSelect) {
- const std::string text = R"(
- ; CHECK-NOT: OpDecorate
- ; CHECK: [[scope:%\w+]] = OpConstant {{%\w+}} 5
- ; CHECK: OpLoad {{%\w+}} {{%\w+}} Volatile|MakePointerVisibleKHR|NonPrivatePointerKHR [[scope]]
- ; CHECK: OpStore {{%\w+}} {{%\w+}} Volatile|MakePointerAvailableKHR|NonPrivatePointerKHR [[scope]]
- OpCapability Shader
- OpCapability Linkage
- OpCapability VariablePointers
- OpExtension "SPV_KHR_variable_pointers"
- OpMemoryModel Logical GLSL450
- OpDecorate %var Coherent
- OpDecorate %var Volatile
- %void = OpTypeVoid
- %int = OpTypeInt 32 0
- %bool = OpTypeBool
- %true = OpConstantTrue %bool
- %ptr_int_StorageBuffer = OpTypePointer StorageBuffer %int
- %null = OpConstantNull %ptr_int_StorageBuffer
- %var = OpVariable %ptr_int_StorageBuffer StorageBuffer
- %func_ty = OpTypeFunction %void
- %func = OpFunction %void None %func_ty
- %1 = OpLabel
- %select = OpSelect %ptr_int_StorageBuffer %true %var %null
- %ld = OpLoad %int %select
- OpStore %var %ld
- OpReturn
- OpFunctionEnd
- )";
- SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true);
- }
- TEST_F(UpgradeMemoryModelTest, VariablePointerSelectConservative) {
- const std::string text = R"(
- ; CHECK-NOT: OpDecorate
- ; CHECK: [[scope:%\w+]] = OpConstant {{%\w+}} 5
- ; CHECK: OpLoad {{%\w+}} {{%\w+}} Volatile|MakePointerVisibleKHR|NonPrivatePointerKHR [[scope]]
- ; CHECK: OpStore {{%\w+}} {{%\w+}} Volatile|MakePointerAvailableKHR|NonPrivatePointerKHR [[scope]]
- OpCapability Shader
- OpCapability Linkage
- OpCapability VariablePointers
- OpExtension "SPV_KHR_variable_pointers"
- OpMemoryModel Logical GLSL450
- OpDecorate %var1 Coherent
- OpDecorate %var2 Volatile
- %void = OpTypeVoid
- %int = OpTypeInt 32 0
- %bool = OpTypeBool
- %true = OpConstantTrue %bool
- %ptr_int_StorageBuffer = OpTypePointer StorageBuffer %int
- %var1 = OpVariable %ptr_int_StorageBuffer StorageBuffer
- %var2 = OpVariable %ptr_int_StorageBuffer StorageBuffer
- %func_ty = OpTypeFunction %void
- %func = OpFunction %void None %func_ty
- %1 = OpLabel
- %select = OpSelect %ptr_int_StorageBuffer %true %var1 %var2
- %ld = OpLoad %int %select
- OpStore %select %ld
- OpReturn
- OpFunctionEnd
- )";
- SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true);
- }
- TEST_F(UpgradeMemoryModelTest, VariablePointerIncrement) {
- const std::string text = R"(
- ; CHECK-NOT: OpDecorate {{%\w+}} Coherent
- ; CHECK: [[scope:%\w+]] = OpConstant {{%\w+}} 5
- ; CHECK: OpLoad {{%\w+}} {{%\w+}} MakePointerVisibleKHR|NonPrivatePointerKHR [[scope]]
- ; CHECK: OpStore {{%\w+}} {{%\w+}} MakePointerAvailableKHR|NonPrivatePointerKHR [[scope]]
- OpCapability Shader
- OpCapability Linkage
- OpCapability VariablePointers
- OpExtension "SPV_KHR_variable_pointers"
- OpMemoryModel Logical GLSL450
- OpDecorate %param Coherent
- OpDecorate %param ArrayStride 4
- %void = OpTypeVoid
- %bool = OpTypeBool
- %int = OpTypeInt 32 0
- %int0 = OpConstant %int 0
- %int1 = OpConstant %int 1
- %int10 = OpConstant %int 10
- %ptr_int_StorageBuffer = OpTypePointer StorageBuffer %int
- %func_ty = OpTypeFunction %void %ptr_int_StorageBuffer
- %func = OpFunction %void None %func_ty
- %param = OpFunctionParameter %ptr_int_StorageBuffer
- %1 = OpLabel
- OpBranch %2
- %2 = OpLabel
- %phi = OpPhi %ptr_int_StorageBuffer %param %1 %ptr_next %2
- %iv = OpPhi %int %int0 %1 %inc %2
- %inc = OpIAdd %int %iv %int1
- %ptr_next = OpPtrAccessChain %ptr_int_StorageBuffer %phi %int1
- %cmp = OpIEqual %bool %iv %int10
- OpLoopMerge %3 %2 None
- OpBranchConditional %cmp %3 %2
- %3 = OpLabel
- %ld = OpLoad %int %phi
- OpStore %phi %ld
- OpReturn
- OpFunctionEnd
- )";
- SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true);
- }
- TEST_F(UpgradeMemoryModelTest, CoherentStructElement) {
- const std::string text = R"(
- ; CHECK-NOT: OpMemberDecorate
- ; CHECK: [[scope:%\w+]] = OpConstant {{%\w+}} 5
- ; CHECK: OpLoad {{%\w+}} {{%\w+}} MakePointerVisibleKHR|NonPrivatePointerKHR [[scope]]
- ; CHECK: OpStore {{%\w+}} {{%\w+}} MakePointerAvailableKHR|NonPrivatePointerKHR [[scope]]
- OpCapability Shader
- OpCapability Linkage
- OpExtension "SPV_KHR_storage_buffer_storage_class"
- OpMemoryModel Logical GLSL450
- OpMemberDecorate %struct 0 Coherent
- %void = OpTypeVoid
- %int = OpTypeInt 32 0
- %int0 = OpConstant %int 0
- %struct = OpTypeStruct %int
- %ptr_struct_StorageBuffer = OpTypePointer StorageBuffer %struct
- %ptr_int_StorageBuffer = OpTypePointer StorageBuffer %int
- %func_ty = OpTypeFunction %void %ptr_struct_StorageBuffer
- %func = OpFunction %void None %func_ty
- %param = OpFunctionParameter %ptr_struct_StorageBuffer
- %1 = OpLabel
- %gep = OpAccessChain %ptr_int_StorageBuffer %param %int0
- %ld = OpLoad %int %gep
- OpStore %gep %ld
- OpReturn
- OpFunctionEnd
- )";
- SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true);
- }
- TEST_F(UpgradeMemoryModelTest, CoherentElementFullStructAccess) {
- const std::string text = R"(
- ; CHECK-NOT: OpMemberDecorate
- ; CHECK: [[scope:%\w+]] = OpConstant {{%\w+}} 5
- ; CHECK: OpLoad {{%\w+}} {{%\w+}} MakePointerVisibleKHR|NonPrivatePointerKHR [[scope]]
- ; CHECK: OpStore {{%\w+}} {{%\w+}} MakePointerAvailableKHR|NonPrivatePointerKHR [[scope]]
- OpCapability Shader
- OpCapability Linkage
- OpExtension "SPV_KHR_storage_buffer_storage_class"
- OpMemoryModel Logical GLSL450
- OpMemberDecorate %struct 0 Coherent
- %void = OpTypeVoid
- %int = OpTypeInt 32 0
- %struct = OpTypeStruct %int
- %ptr_struct_StorageBuffer = OpTypePointer StorageBuffer %struct
- %func_ty = OpTypeFunction %void %ptr_struct_StorageBuffer
- %func = OpFunction %void None %func_ty
- %param = OpFunctionParameter %ptr_struct_StorageBuffer
- %1 = OpLabel
- %ld = OpLoad %struct %param
- OpStore %param %ld
- OpReturn
- OpFunctionEnd
- )";
- SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true);
- }
- TEST_F(UpgradeMemoryModelTest, CoherentElementNotAccessed) {
- const std::string text = R"(
- ; CHECK-NOT: OpMemberDecorate
- ; CHECK-NOT: MakePointerAvailableKHR
- ; CHECK-NOT: NonPrivatePointerKHR
- ; CHECK-NOT: MakePointerVisibleKHR
- OpCapability Shader
- OpCapability Linkage
- OpExtension "SPV_KHR_storage_buffer_storage_class"
- OpMemoryModel Logical GLSL450
- OpMemberDecorate %struct 1 Coherent
- %void = OpTypeVoid
- %int = OpTypeInt 32 0
- %int0 = OpConstant %int 0
- %struct = OpTypeStruct %int %int
- %ptr_struct_StorageBuffer = OpTypePointer StorageBuffer %struct
- %ptr_int_StorageBuffer = OpTypePointer StorageBuffer %int
- %func_ty = OpTypeFunction %void %ptr_struct_StorageBuffer
- %func = OpFunction %void None %func_ty
- %param = OpFunctionParameter %ptr_struct_StorageBuffer
- %1 = OpLabel
- %gep = OpAccessChain %ptr_int_StorageBuffer %param %int0
- %ld = OpLoad %int %gep
- OpStore %gep %ld
- OpReturn
- OpFunctionEnd
- )";
- SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true);
- }
- TEST_F(UpgradeMemoryModelTest, MultiIndexAccessCoherent) {
- const std::string text = R"(
- ; CHECK-NOT: OpMemberDecorate
- ; CHECK: [[scope:%\w+]] = OpConstant {{%\w+}} 5
- ; CHECK: OpLoad {{%\w+}} {{%\w+}} MakePointerVisibleKHR|NonPrivatePointerKHR [[scope]]
- ; CHECK: OpStore {{%\w+}} {{%\w+}} MakePointerAvailableKHR|NonPrivatePointerKHR [[scope]]
- OpCapability Shader
- OpCapability Linkage
- OpExtension "SPV_KHR_storage_buffer_storage_class"
- OpMemoryModel Logical GLSL450
- OpMemberDecorate %inner 1 Coherent
- %void = OpTypeVoid
- %int = OpTypeInt 32 0
- %int0 = OpConstant %int 0
- %int1 = OpConstant %int 1
- %inner = OpTypeStruct %int %int
- %middle = OpTypeStruct %inner
- %outer = OpTypeStruct %middle %middle
- %ptr_outer_StorageBuffer = OpTypePointer StorageBuffer %outer
- %ptr_int_StorageBuffer = OpTypePointer StorageBuffer %int
- %func_ty = OpTypeFunction %void %ptr_outer_StorageBuffer
- %func = OpFunction %void None %func_ty
- %param = OpFunctionParameter %ptr_outer_StorageBuffer
- %1 = OpLabel
- %ld_gep = OpInBoundsAccessChain %ptr_int_StorageBuffer %param %int0 %int0 %int1
- %ld = OpLoad %int %ld_gep
- %st_gep = OpInBoundsAccessChain %ptr_int_StorageBuffer %param %int1 %int0 %int1
- OpStore %st_gep %ld
- OpReturn
- OpFunctionEnd
- )";
- SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true);
- }
- TEST_F(UpgradeMemoryModelTest, MultiIndexAccessNonCoherent) {
- const std::string text = R"(
- ; CHECK-NOT: OpMemberDecorate
- ; CHECK-NOT: MakePointerAvailableKHR
- ; CHECK-NOT: NonPrivatePointerKHR
- ; CHECK-NOT: MakePointerVisibleKHR
- OpCapability Shader
- OpCapability Linkage
- OpExtension "SPV_KHR_storage_buffer_storage_class"
- OpMemoryModel Logical GLSL450
- OpMemberDecorate %inner 1 Coherent
- %void = OpTypeVoid
- %int = OpTypeInt 32 0
- %int0 = OpConstant %int 0
- %int1 = OpConstant %int 1
- %inner = OpTypeStruct %int %int
- %middle = OpTypeStruct %inner
- %outer = OpTypeStruct %middle %middle
- %ptr_outer_StorageBuffer = OpTypePointer StorageBuffer %outer
- %ptr_int_StorageBuffer = OpTypePointer StorageBuffer %int
- %func_ty = OpTypeFunction %void %ptr_outer_StorageBuffer
- %func = OpFunction %void None %func_ty
- %param = OpFunctionParameter %ptr_outer_StorageBuffer
- %1 = OpLabel
- %ld_gep = OpInBoundsAccessChain %ptr_int_StorageBuffer %param %int0 %int0 %int0
- %ld = OpLoad %int %ld_gep
- %st_gep = OpInBoundsAccessChain %ptr_int_StorageBuffer %param %int1 %int0 %int0
- OpStore %st_gep %ld
- OpReturn
- OpFunctionEnd
- )";
- SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true);
- }
- TEST_F(UpgradeMemoryModelTest, ConsecutiveAccessChainCoherent) {
- const std::string text = R"(
- ; CHECK-NOT: OpMemberDecorate
- ; CHECK: [[scope:%\w+]] = OpConstant {{%\w+}} 5
- ; CHECK: OpLoad {{%\w+}} {{%\w+}} MakePointerVisibleKHR|NonPrivatePointerKHR [[scope]]
- ; CHECK: OpStore {{%\w+}} {{%\w+}} MakePointerAvailableKHR|NonPrivatePointerKHR [[scope]]
- OpCapability Shader
- OpCapability Linkage
- OpExtension "SPV_KHR_storage_buffer_storage_class"
- OpMemoryModel Logical GLSL450
- OpMemberDecorate %inner 1 Coherent
- %void = OpTypeVoid
- %int = OpTypeInt 32 0
- %int0 = OpConstant %int 0
- %int1 = OpConstant %int 1
- %inner = OpTypeStruct %int %int
- %middle = OpTypeStruct %inner
- %outer = OpTypeStruct %middle %middle
- %ptr_outer_StorageBuffer = OpTypePointer StorageBuffer %outer
- %ptr_middle_StorageBuffer = OpTypePointer StorageBuffer %middle
- %ptr_inner_StorageBuffer = OpTypePointer StorageBuffer %inner
- %ptr_int_StorageBuffer = OpTypePointer StorageBuffer %int
- %func_ty = OpTypeFunction %void %ptr_outer_StorageBuffer
- %func = OpFunction %void None %func_ty
- %param = OpFunctionParameter %ptr_outer_StorageBuffer
- %1 = OpLabel
- %ld_gep1 = OpInBoundsAccessChain %ptr_middle_StorageBuffer %param %int0
- %ld_gep2 = OpInBoundsAccessChain %ptr_inner_StorageBuffer %ld_gep1 %int0
- %ld_gep3 = OpInBoundsAccessChain %ptr_int_StorageBuffer %ld_gep2 %int1
- %ld = OpLoad %int %ld_gep3
- %st_gep1 = OpInBoundsAccessChain %ptr_middle_StorageBuffer %param %int1
- %st_gep2 = OpInBoundsAccessChain %ptr_inner_StorageBuffer %st_gep1 %int0
- %st_gep3 = OpInBoundsAccessChain %ptr_int_StorageBuffer %st_gep2 %int1
- OpStore %st_gep3 %ld
- OpReturn
- OpFunctionEnd
- )";
- SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true);
- }
- TEST_F(UpgradeMemoryModelTest, ConsecutiveAccessChainNonCoherent) {
- const std::string text = R"(
- ; CHECK-NOT: OpMemberDecorate
- ; CHECK-NOT: MakePointerAvailableKHR
- ; CHECK-NOT: NonPrivatePointerKHR
- ; CHECK-NOT: MakePointerVisibleKHR
- OpCapability Shader
- OpCapability Linkage
- OpExtension "SPV_KHR_storage_buffer_storage_class"
- OpMemoryModel Logical GLSL450
- OpMemberDecorate %inner 1 Coherent
- %void = OpTypeVoid
- %int = OpTypeInt 32 0
- %int0 = OpConstant %int 0
- %int1 = OpConstant %int 1
- %inner = OpTypeStruct %int %int
- %middle = OpTypeStruct %inner
- %outer = OpTypeStruct %middle %middle
- %ptr_outer_StorageBuffer = OpTypePointer StorageBuffer %outer
- %ptr_middle_StorageBuffer = OpTypePointer StorageBuffer %middle
- %ptr_inner_StorageBuffer = OpTypePointer StorageBuffer %inner
- %ptr_int_StorageBuffer = OpTypePointer StorageBuffer %int
- %func_ty = OpTypeFunction %void %ptr_outer_StorageBuffer
- %func = OpFunction %void None %func_ty
- %param = OpFunctionParameter %ptr_outer_StorageBuffer
- %1 = OpLabel
- %ld_gep1 = OpInBoundsAccessChain %ptr_middle_StorageBuffer %param %int0
- %ld_gep2 = OpInBoundsAccessChain %ptr_inner_StorageBuffer %ld_gep1 %int0
- %ld_gep3 = OpInBoundsAccessChain %ptr_int_StorageBuffer %ld_gep2 %int0
- %ld = OpLoad %int %ld_gep3
- %st_gep1 = OpInBoundsAccessChain %ptr_middle_StorageBuffer %param %int1
- %st_gep2 = OpInBoundsAccessChain %ptr_inner_StorageBuffer %st_gep1 %int0
- %st_gep3 = OpInBoundsAccessChain %ptr_int_StorageBuffer %st_gep2 %int0
- OpStore %st_gep3 %ld
- OpReturn
- OpFunctionEnd
- )";
- SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true);
- }
- TEST_F(UpgradeMemoryModelTest, CoherentStructElementAccess) {
- const std::string text = R"(
- ; CHECK-NOT: OpMemberDecorate
- ; CHECK: [[scope:%\w+]] = OpConstant {{%\w+}} 5
- ; CHECK: OpLoad {{%\w+}} {{%\w+}} MakePointerVisibleKHR|NonPrivatePointerKHR [[scope]]
- ; CHECK: OpStore {{%\w+}} {{%\w+}} MakePointerAvailableKHR|NonPrivatePointerKHR [[scope]]
- OpCapability Shader
- OpCapability Linkage
- OpExtension "SPV_KHR_storage_buffer_storage_class"
- OpMemoryModel Logical GLSL450
- OpMemberDecorate %middle 0 Coherent
- %void = OpTypeVoid
- %int = OpTypeInt 32 0
- %int0 = OpConstant %int 0
- %int1 = OpConstant %int 1
- %inner = OpTypeStruct %int %int
- %middle = OpTypeStruct %inner
- %outer = OpTypeStruct %middle %middle
- %ptr_outer_StorageBuffer = OpTypePointer StorageBuffer %outer
- %ptr_middle_StorageBuffer = OpTypePointer StorageBuffer %middle
- %ptr_inner_StorageBuffer = OpTypePointer StorageBuffer %inner
- %ptr_int_StorageBuffer = OpTypePointer StorageBuffer %int
- %func_ty = OpTypeFunction %void %ptr_outer_StorageBuffer
- %func = OpFunction %void None %func_ty
- %param = OpFunctionParameter %ptr_outer_StorageBuffer
- %1 = OpLabel
- %ld_gep1 = OpInBoundsAccessChain %ptr_middle_StorageBuffer %param %int0
- %ld_gep2 = OpInBoundsAccessChain %ptr_inner_StorageBuffer %ld_gep1 %int0
- %ld_gep3 = OpInBoundsAccessChain %ptr_int_StorageBuffer %ld_gep2 %int1
- %ld = OpLoad %int %ld_gep3
- %st_gep1 = OpInBoundsAccessChain %ptr_middle_StorageBuffer %param %int1
- %st_gep2 = OpInBoundsAccessChain %ptr_inner_StorageBuffer %st_gep1 %int0
- %st_gep3 = OpInBoundsAccessChain %ptr_int_StorageBuffer %st_gep2 %int1
- OpStore %st_gep3 %ld
- OpReturn
- OpFunctionEnd
- )";
- SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true);
- }
- TEST_F(UpgradeMemoryModelTest, NonCoherentLoadCoherentStore) {
- const std::string text = R"(
- ; CHECK-NOT: OpMemberDecorate
- ; CHECK: [[scope:%\w+]] = OpConstant {{%\w+}} 5
- ; CHECK-NOT: MakePointerVisibleKHR
- ; CHECK: OpStore {{%\w+}} {{%\w+}} MakePointerAvailableKHR|NonPrivatePointerKHR [[scope]]
- OpCapability Shader
- OpCapability Linkage
- OpExtension "SPV_KHR_storage_buffer_storage_class"
- OpMemoryModel Logical GLSL450
- OpMemberDecorate %outer 1 Coherent
- %void = OpTypeVoid
- %int = OpTypeInt 32 0
- %int0 = OpConstant %int 0
- %int1 = OpConstant %int 1
- %inner = OpTypeStruct %int %int
- %middle = OpTypeStruct %inner
- %outer = OpTypeStruct %middle %middle
- %ptr_outer_StorageBuffer = OpTypePointer StorageBuffer %outer
- %ptr_middle_StorageBuffer = OpTypePointer StorageBuffer %middle
- %ptr_inner_StorageBuffer = OpTypePointer StorageBuffer %inner
- %ptr_int_StorageBuffer = OpTypePointer StorageBuffer %int
- %func_ty = OpTypeFunction %void %ptr_outer_StorageBuffer
- %func = OpFunction %void None %func_ty
- %param = OpFunctionParameter %ptr_outer_StorageBuffer
- %1 = OpLabel
- %ld_gep1 = OpInBoundsAccessChain %ptr_middle_StorageBuffer %param %int0
- %ld_gep2 = OpInBoundsAccessChain %ptr_inner_StorageBuffer %ld_gep1 %int0
- %ld_gep3 = OpInBoundsAccessChain %ptr_int_StorageBuffer %ld_gep2 %int1
- %ld = OpLoad %int %ld_gep3
- %st_gep1 = OpInBoundsAccessChain %ptr_middle_StorageBuffer %param %int1
- %st_gep2 = OpInBoundsAccessChain %ptr_inner_StorageBuffer %st_gep1 %int0
- %st_gep3 = OpInBoundsAccessChain %ptr_int_StorageBuffer %st_gep2 %int1
- OpStore %st_gep3 %ld
- OpReturn
- OpFunctionEnd
- )";
- SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true);
- }
- TEST_F(UpgradeMemoryModelTest, CopyMemory) {
- const std::string text = R"(
- ; CHECK-NOT: OpDecorate
- ; CHECK: [[queuefamily:%\w+]] = OpConstant {{%\w+}} 5
- ; CHECK: OpCopyMemory {{%\w+}} {{%\w+}} Volatile|MakePointerVisibleKHR|NonPrivatePointerKHR [[queuefamily]]
- ; CHECK-NOT: [[queuefamily]]
- OpCapability Shader
- OpCapability Linkage
- OpExtension "SPV_KHR_storage_buffer_storage_class"
- OpMemoryModel Logical GLSL450
- OpDecorate %in_var Coherent
- OpDecorate %out_var Volatile
- %void = OpTypeVoid
- %int = OpTypeInt 32 0
- %ptr_int_StorageBuffer = OpTypePointer StorageBuffer %int
- %in_var = OpVariable %ptr_int_StorageBuffer StorageBuffer
- %out_var = OpVariable %ptr_int_StorageBuffer StorageBuffer
- %func_ty = OpTypeFunction %void
- %func = OpFunction %void None %func_ty
- %1 = OpLabel
- OpCopyMemory %out_var %in_var
- OpReturn
- OpFunctionEnd
- )";
- SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true);
- }
- TEST_F(UpgradeMemoryModelTest, CopyMemorySized) {
- const std::string text = R"(
- ; CHECK-NOT: OpDecorate
- ; CHECK: [[queuefamily:%\w+]] = OpConstant {{%\w+}} 5
- ; CHECK: OpCopyMemorySized {{%\w+}} {{%\w+}} {{%\w+}} Volatile|MakePointerAvailableKHR|NonPrivatePointerKHR [[queuefamily]]
- ; CHECK-NOT: [[queuefamily]]
- OpCapability Shader
- OpCapability Linkage
- OpCapability Addresses
- OpExtension "SPV_KHR_storage_buffer_storage_class"
- OpMemoryModel Logical GLSL450
- OpDecorate %out_param Coherent
- OpDecorate %in_param Volatile
- %void = OpTypeVoid
- %int = OpTypeInt 32 0
- %int4 = OpConstant %int 4
- %ptr_int_StorageBuffer = OpTypePointer StorageBuffer %int
- %func_ty = OpTypeFunction %void %ptr_int_StorageBuffer %ptr_int_StorageBuffer
- %func = OpFunction %void None %func_ty
- %in_param = OpFunctionParameter %ptr_int_StorageBuffer
- %out_param = OpFunctionParameter %ptr_int_StorageBuffer
- %1 = OpLabel
- OpCopyMemorySized %out_param %in_param %int4
- OpReturn
- OpFunctionEnd
- )";
- SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true);
- }
- TEST_F(UpgradeMemoryModelTest, CopyMemoryTwoScopes) {
- const std::string text = R"(
- ; CHECK-NOT: OpDecorate
- ; CHECK-DAG: [[queuefamily:%\w+]] = OpConstant {{%\w+}} 5
- ; CHECK-DAG: [[workgroup:%\w+]] = OpConstant {{%\w+}} 2
- ; CHECK: OpCopyMemory {{%\w+}} {{%\w+}} MakePointerAvailableKHR|MakePointerVisibleKHR|NonPrivatePointerKHR [[workgroup]] [[queuefamily]]
- OpCapability Shader
- OpCapability Linkage
- OpExtension "SPV_KHR_storage_buffer_storage_class"
- OpMemoryModel Logical GLSL450
- OpDecorate %in_var Coherent
- OpDecorate %out_var Coherent
- %void = OpTypeVoid
- %int = OpTypeInt 32 0
- %ptr_int_Workgroup = OpTypePointer Workgroup %int
- %ptr_int_StorageBuffer = OpTypePointer StorageBuffer %int
- %in_var = OpVariable %ptr_int_StorageBuffer StorageBuffer
- %out_var = OpVariable %ptr_int_Workgroup Workgroup
- %func_ty = OpTypeFunction %void
- %func = OpFunction %void None %func_ty
- %1 = OpLabel
- OpCopyMemory %out_var %in_var
- OpReturn
- OpFunctionEnd
- )";
- SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true);
- }
- TEST_F(UpgradeMemoryModelTest, VolatileImageRead) {
- const std::string text = R"(
- ; CHECK-NOT: OpDecorate
- ; CHECK: OpLoad {{%\w+}} {{%\w+}} Volatile
- ; CHECK: OpImageRead {{%\w+}} {{%\w+}} {{%\w+}} VolatileTexelKHR
- OpCapability Shader
- OpCapability Linkage
- OpCapability StorageImageReadWithoutFormat
- OpExtension "SPV_KHR_storage_buffer_storage_class"
- OpMemoryModel Logical GLSL450
- OpDecorate %var Volatile
- %void = OpTypeVoid
- %int = OpTypeInt 32 0
- %v2int = OpTypeVector %int 2
- %float = OpTypeFloat 32
- %int0 = OpConstant %int 0
- %v2int_0 = OpConstantComposite %v2int %int0 %int0
- %image = OpTypeImage %float 2D 0 0 0 2 Unknown
- %ptr_image_StorageBuffer = OpTypePointer StorageBuffer %image
- %var = OpVariable %ptr_image_StorageBuffer StorageBuffer
- %func_ty = OpTypeFunction %void
- %func = OpFunction %void None %func_ty
- %1 = OpLabel
- %ld = OpLoad %image %var
- %rd = OpImageRead %float %ld %v2int_0
- OpReturn
- OpFunctionEnd
- )";
- SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true);
- }
- TEST_F(UpgradeMemoryModelTest, CoherentImageRead) {
- const std::string text = R"(
- ; CHECK-NOT: OpDecorate
- ; CHECK: [[scope:%\w+]] = OpConstant {{%\w+}} 5
- ; CHECK: OpLoad {{%\w+}} {{%\w+}} MakePointerVisibleKHR|NonPrivatePointerKHR [[scope]]
- ; CHECK: OpImageRead {{%\w+}} {{%\w+}} {{%\w+}} MakeTexelVisibleKHR|NonPrivateTexelKHR [[scope]]
- OpCapability Shader
- OpCapability Linkage
- OpCapability StorageImageReadWithoutFormat
- OpExtension "SPV_KHR_storage_buffer_storage_class"
- OpMemoryModel Logical GLSL450
- OpDecorate %var Coherent
- %void = OpTypeVoid
- %int = OpTypeInt 32 0
- %v2int = OpTypeVector %int 2
- %float = OpTypeFloat 32
- %int0 = OpConstant %int 0
- %v2int_0 = OpConstantComposite %v2int %int0 %int0
- %image = OpTypeImage %float 2D 0 0 0 2 Unknown
- %ptr_image_StorageBuffer = OpTypePointer StorageBuffer %image
- %var = OpVariable %ptr_image_StorageBuffer StorageBuffer
- %func_ty = OpTypeFunction %void
- %func = OpFunction %void None %func_ty
- %1 = OpLabel
- %ld = OpLoad %image %var
- %rd = OpImageRead %float %ld %v2int_0
- OpReturn
- OpFunctionEnd
- )";
- SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true);
- }
- TEST_F(UpgradeMemoryModelTest, CoherentImageReadExtractedFromSampledImage) {
- const std::string text = R"(
- ; CHECK-NOT: OpDecorate
- ; CHECK: [[image:%\w+]] = OpTypeImage
- ; CHECK: [[scope:%\w+]] = OpConstant {{%\w+}} 5
- ; CHECK: OpLoad [[image]] {{%\w+}} MakePointerVisibleKHR|NonPrivatePointerKHR [[scope]]
- ; CHECK-NOT: NonPrivatePointerKHR
- ; CHECK: OpImageRead {{%\w+}} {{%\w+}} {{%\w+}} MakeTexelVisibleKHR|NonPrivateTexelKHR [[scope]]
- OpCapability Shader
- OpCapability Linkage
- OpCapability StorageImageReadWithoutFormat
- OpExtension "SPV_KHR_storage_buffer_storage_class"
- OpMemoryModel Logical GLSL450
- OpDecorate %var Coherent
- %void = OpTypeVoid
- %int = OpTypeInt 32 0
- %v2int = OpTypeVector %int 2
- %float = OpTypeFloat 32
- %int0 = OpConstant %int 0
- %v2int_0 = OpConstantComposite %v2int %int0 %int0
- %image = OpTypeImage %float 2D 0 0 0 0 Unknown
- %sampled_image = OpTypeSampledImage %image
- %sampler = OpTypeSampler
- %ptr_image_StorageBuffer = OpTypePointer StorageBuffer %image
- %ptr_sampler_StorageBuffer = OpTypePointer StorageBuffer %sampler
- %var = OpVariable %ptr_image_StorageBuffer StorageBuffer
- %sampler_var = OpVariable %ptr_sampler_StorageBuffer StorageBuffer
- %func_ty = OpTypeFunction %void
- %func = OpFunction %void None %func_ty
- %1 = OpLabel
- %ld = OpLoad %image %var
- %ld_sampler = OpLoad %sampler %sampler_var
- %sample = OpSampledImage %sampled_image %ld %ld_sampler
- %extract = OpImage %image %sample
- %rd = OpImageRead %float %extract %v2int_0
- OpReturn
- OpFunctionEnd
- )";
- SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true);
- }
- TEST_F(UpgradeMemoryModelTest, VolatileImageWrite) {
- const std::string text = R"(
- ; CHECK-NOT: OpDecorate
- ; CHECK: OpLoad {{%\w+}} {{%\w+}} Volatile
- ; CHECK: OpImageWrite {{%\w+}} {{%\w+}} {{%\w+}} VolatileTexelKHR
- OpCapability Shader
- OpCapability Linkage
- OpCapability StorageImageWriteWithoutFormat
- OpExtension "SPV_KHR_storage_buffer_storage_class"
- OpMemoryModel Logical GLSL450
- OpDecorate %param Volatile
- %void = OpTypeVoid
- %int = OpTypeInt 32 0
- %v2int = OpTypeVector %int 2
- %float = OpTypeFloat 32
- %float0 = OpConstant %float 0
- %v2int_null = OpConstantNull %v2int
- %image = OpTypeImage %float 2D 0 0 0 0 Unknown
- %ptr_image_StorageBuffer = OpTypePointer StorageBuffer %image
- %func_ty = OpTypeFunction %void %ptr_image_StorageBuffer
- %func = OpFunction %void None %func_ty
- %param = OpFunctionParameter %ptr_image_StorageBuffer
- %1 = OpLabel
- %ld = OpLoad %image %param
- OpImageWrite %ld %v2int_null %float0
- OpReturn
- OpFunctionEnd
- )";
- SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true);
- }
- TEST_F(UpgradeMemoryModelTest, CoherentImageWrite) {
- const std::string text = R"(
- ; CHECK-NOT: OpDecorate
- ; CHECK: [[scope:%\w+]] = OpConstant {{%\w+}} 5
- ; CHECK: OpLoad {{%\w+}} {{%\w+}} MakePointerVisibleKHR|NonPrivatePointerKHR
- ; CHECK: OpImageWrite {{%\w+}} {{%\w+}} {{%\w+}} MakeTexelAvailableKHR|NonPrivateTexelKHR [[scope]]
- OpCapability Shader
- OpCapability Linkage
- OpCapability StorageImageWriteWithoutFormat
- OpExtension "SPV_KHR_storage_buffer_storage_class"
- OpMemoryModel Logical GLSL450
- OpDecorate %param Coherent
- %void = OpTypeVoid
- %int = OpTypeInt 32 0
- %v2int = OpTypeVector %int 2
- %float = OpTypeFloat 32
- %float0 = OpConstant %float 0
- %v2int_null = OpConstantNull %v2int
- %image = OpTypeImage %float 2D 0 0 0 0 Unknown
- %ptr_image_StorageBuffer = OpTypePointer StorageBuffer %image
- %func_ty = OpTypeFunction %void %ptr_image_StorageBuffer
- %func = OpFunction %void None %func_ty
- %param = OpFunctionParameter %ptr_image_StorageBuffer
- %1 = OpLabel
- %ld = OpLoad %image %param
- OpImageWrite %ld %v2int_null %float0
- OpReturn
- OpFunctionEnd
- )";
- SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true);
- }
- TEST_F(UpgradeMemoryModelTest, CoherentImageWriteExtractFromSampledImage) {
- const std::string text = R"(
- ; CHECK-NOT: OpDecorate
- ; CHECK: [[scope:%\w+]] = OpConstant {{%\w+}} 5
- ; CHECK: OpLoad {{%\w+}} {{%\w+}} MakePointerVisibleKHR|NonPrivatePointerKHR
- ; CHECK-NOT: NonPrivatePointerKHR
- ; CHECK: OpImageWrite {{%\w+}} {{%\w+}} {{%\w+}} MakeTexelAvailableKHR|NonPrivateTexelKHR [[scope]]
- OpCapability Shader
- OpCapability Linkage
- OpCapability StorageImageWriteWithoutFormat
- OpExtension "SPV_KHR_storage_buffer_storage_class"
- OpMemoryModel Logical GLSL450
- OpDecorate %param Coherent
- %void = OpTypeVoid
- %int = OpTypeInt 32 0
- %v2int = OpTypeVector %int 2
- %float = OpTypeFloat 32
- %float0 = OpConstant %float 0
- %v2int_null = OpConstantNull %v2int
- %image = OpTypeImage %float 2D 0 0 0 0 Unknown
- %sampled_image = OpTypeSampledImage %image
- %sampler = OpTypeSampler
- %ptr_image_StorageBuffer = OpTypePointer StorageBuffer %image
- %ptr_sampler_StorageBuffer = OpTypePointer StorageBuffer %sampler
- %func_ty = OpTypeFunction %void %ptr_image_StorageBuffer %ptr_sampler_StorageBuffer
- %func = OpFunction %void None %func_ty
- %param = OpFunctionParameter %ptr_image_StorageBuffer
- %sampler_param = OpFunctionParameter %ptr_sampler_StorageBuffer
- %1 = OpLabel
- %ld = OpLoad %image %param
- %ld_sampler = OpLoad %sampler %sampler_param
- %sample = OpSampledImage %sampled_image %ld %ld_sampler
- %extract = OpImage %image %sample
- OpImageWrite %extract %v2int_null %float0
- OpReturn
- OpFunctionEnd
- )";
- SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true);
- }
- TEST_F(UpgradeMemoryModelTest, VolatileImageSparseRead) {
- const std::string text = R"(
- ; CHECK-NOT: OpDecorate
- ; CHECK: OpLoad {{%\w+}} {{%\w+}} Volatile
- ; CHECK: OpImageSparseRead {{%\w+}} {{%\w+}} {{%\w+}} VolatileTexelKHR
- OpCapability Shader
- OpCapability Linkage
- OpCapability StorageImageReadWithoutFormat
- OpCapability SparseResidency
- OpExtension "SPV_KHR_storage_buffer_storage_class"
- OpMemoryModel Logical GLSL450
- OpDecorate %var Volatile
- %void = OpTypeVoid
- %int = OpTypeInt 32 0
- %v2int = OpTypeVector %int 2
- %float = OpTypeFloat 32
- %int0 = OpConstant %int 0
- %v2int_0 = OpConstantComposite %v2int %int0 %int0
- %image = OpTypeImage %float 2D 0 0 0 2 Unknown
- %struct = OpTypeStruct %int %float
- %ptr_image_StorageBuffer = OpTypePointer StorageBuffer %image
- %var = OpVariable %ptr_image_StorageBuffer StorageBuffer
- %func_ty = OpTypeFunction %void
- %func = OpFunction %void None %func_ty
- %1 = OpLabel
- %ld = OpLoad %image %var
- %rd = OpImageSparseRead %struct %ld %v2int_0
- OpReturn
- OpFunctionEnd
- )";
- SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true);
- }
- TEST_F(UpgradeMemoryModelTest, CoherentImageSparseRead) {
- const std::string text = R"(
- ; CHECK-NOT: OpDecorate
- ; CHECK: [[scope:%\w+]] = OpConstant {{%\w+}} 5
- ; CHECK: OpLoad {{%\w+}} {{%\w+}} MakePointerVisibleKHR|NonPrivatePointerKHR [[scope]]
- ; CHECK: OpImageSparseRead {{%\w+}} {{%\w+}} {{%\w+}} MakeTexelVisibleKHR|NonPrivateTexelKHR [[scope]]
- OpCapability Shader
- OpCapability Linkage
- OpCapability StorageImageReadWithoutFormat
- OpCapability SparseResidency
- OpExtension "SPV_KHR_storage_buffer_storage_class"
- OpMemoryModel Logical GLSL450
- OpDecorate %var Coherent
- %void = OpTypeVoid
- %int = OpTypeInt 32 0
- %v2int = OpTypeVector %int 2
- %float = OpTypeFloat 32
- %int0 = OpConstant %int 0
- %v2int_0 = OpConstantComposite %v2int %int0 %int0
- %image = OpTypeImage %float 2D 0 0 0 2 Unknown
- %struct = OpTypeStruct %int %float
- %ptr_image_StorageBuffer = OpTypePointer StorageBuffer %image
- %var = OpVariable %ptr_image_StorageBuffer StorageBuffer
- %func_ty = OpTypeFunction %void
- %func = OpFunction %void None %func_ty
- %1 = OpLabel
- %ld = OpLoad %image %var
- %rd = OpImageSparseRead %struct %ld %v2int_0
- OpReturn
- OpFunctionEnd
- )";
- SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true);
- }
- TEST_F(UpgradeMemoryModelTest,
- CoherentImageSparseReadExtractedFromSampledImage) {
- const std::string text = R"(
- ; CHECK-NOT: OpDecorate
- ; CHECK: [[image:%\w+]] = OpTypeImage
- ; CHECK: [[scope:%\w+]] = OpConstant {{%\w+}} 5
- ; CHECK: OpLoad [[image]] {{%\w+}} MakePointerVisibleKHR|NonPrivatePointerKHR [[scope]]
- ; CHECK-NOT: NonPrivatePointerKHR
- ; CHECK: OpImageSparseRead {{%\w+}} {{%\w+}} {{%\w+}} MakeTexelVisibleKHR|NonPrivateTexelKHR [[scope]]
- OpCapability Shader
- OpCapability Linkage
- OpCapability StorageImageReadWithoutFormat
- OpCapability SparseResidency
- OpExtension "SPV_KHR_storage_buffer_storage_class"
- OpMemoryModel Logical GLSL450
- OpDecorate %var Coherent
- %void = OpTypeVoid
- %int = OpTypeInt 32 0
- %v2int = OpTypeVector %int 2
- %float = OpTypeFloat 32
- %int0 = OpConstant %int 0
- %v2int_0 = OpConstantComposite %v2int %int0 %int0
- %image = OpTypeImage %float 2D 0 0 0 0 Unknown
- %struct = OpTypeStruct %int %float
- %sampled_image = OpTypeSampledImage %image
- %sampler = OpTypeSampler
- %ptr_image_StorageBuffer = OpTypePointer StorageBuffer %image
- %ptr_sampler_StorageBuffer = OpTypePointer StorageBuffer %sampler
- %var = OpVariable %ptr_image_StorageBuffer StorageBuffer
- %sampler_var = OpVariable %ptr_sampler_StorageBuffer StorageBuffer
- %func_ty = OpTypeFunction %void
- %func = OpFunction %void None %func_ty
- %1 = OpLabel
- %ld = OpLoad %image %var
- %ld_sampler = OpLoad %sampler %sampler_var
- %sample = OpSampledImage %sampled_image %ld %ld_sampler
- %extract = OpImage %image %sample
- %rd = OpImageSparseRead %struct %extract %v2int_0
- OpReturn
- OpFunctionEnd
- )";
- SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true);
- }
- TEST_F(UpgradeMemoryModelTest, TessellationControlBarrierNoChange) {
- const std::string text = R"(
- ; CHECK: [[none:%\w+]] = OpConstant {{%\w+}} 0
- ; CHECK: [[workgroup:%\w+]] = OpConstant {{%\w+}} 2
- ; CHECK: OpControlBarrier [[workgroup]] [[workgroup]] [[none]]
- OpCapability Tessellation
- OpMemoryModel Logical GLSL450
- OpEntryPoint TessellationControl %func "func"
- %void = OpTypeVoid
- %int = OpTypeInt 32 0
- %none = OpConstant %int 0
- %workgroup = OpConstant %int 2
- %func_ty = OpTypeFunction %void
- %func = OpFunction %void None %func_ty
- %1 = OpLabel
- OpControlBarrier %workgroup %workgroup %none
- OpReturn
- OpFunctionEnd
- )";
- SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true);
- }
- TEST_F(UpgradeMemoryModelTest, TessellationControlBarrierAddOutput) {
- const std::string text = R"(
- ; CHECK: [[workgroup:%\w+]] = OpConstant {{%\w+}} 2
- ; CHECK: [[output:%\w+]] = OpConstant {{%\w+}} 4096
- ; CHECK: OpControlBarrier [[workgroup]] [[workgroup]] [[output]]
- OpCapability Tessellation
- OpMemoryModel Logical GLSL450
- OpEntryPoint TessellationControl %func "func" %var
- %void = OpTypeVoid
- %int = OpTypeInt 32 0
- %none = OpConstant %int 0
- %workgroup = OpConstant %int 2
- %ptr_int_Output = OpTypePointer Output %int
- %var = OpVariable %ptr_int_Output Output
- %func_ty = OpTypeFunction %void
- %func = OpFunction %void None %func_ty
- %1 = OpLabel
- %ld = OpLoad %int %var
- OpControlBarrier %workgroup %workgroup %none
- OpStore %var %ld
- OpReturn
- OpFunctionEnd
- )";
- SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true);
- }
- TEST_F(UpgradeMemoryModelTest, TessellationMemoryBarrierNoChange) {
- const std::string text = R"(
- ; CHECK: [[none:%\w+]] = OpConstant {{%\w+}} 0
- ; CHECK: [[workgroup:%\w+]] = OpConstant {{%\w+}} 2
- ; CHECK: OpMemoryBarrier [[workgroup]] [[none]]
- OpCapability Tessellation
- OpMemoryModel Logical GLSL450
- OpEntryPoint TessellationControl %func "func" %var
- %void = OpTypeVoid
- %int = OpTypeInt 32 0
- %none = OpConstant %int 0
- %workgroup = OpConstant %int 2
- %ptr_int_Output = OpTypePointer Output %int
- %var = OpVariable %ptr_int_Output Output
- %func_ty = OpTypeFunction %void
- %func = OpFunction %void None %func_ty
- %1 = OpLabel
- %ld = OpLoad %int %var
- OpMemoryBarrier %workgroup %none
- OpStore %var %ld
- OpReturn
- OpFunctionEnd
- )";
- SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true);
- }
- TEST_F(UpgradeMemoryModelTest, TessellationControlBarrierAddOutputSubFunction) {
- const std::string text = R"(
- ; CHECK: [[workgroup:%\w+]] = OpConstant {{%\w+}} 2
- ; CHECK: [[output:%\w+]] = OpConstant {{%\w+}} 4096
- ; CHECK: OpControlBarrier [[workgroup]] [[workgroup]] [[output]]
- OpCapability Tessellation
- OpMemoryModel Logical GLSL450
- OpEntryPoint TessellationControl %func "func" %var
- %void = OpTypeVoid
- %int = OpTypeInt 32 0
- %none = OpConstant %int 0
- %workgroup = OpConstant %int 2
- %ptr_int_Output = OpTypePointer Output %int
- %var = OpVariable %ptr_int_Output Output
- %func_ty = OpTypeFunction %void
- %func = OpFunction %void None %func_ty
- %1 = OpLabel
- %call = OpFunctionCall %void %sub_func
- OpReturn
- OpFunctionEnd
- %sub_func = OpFunction %void None %func_ty
- %2 = OpLabel
- %ld = OpLoad %int %var
- OpControlBarrier %workgroup %workgroup %none
- OpStore %var %ld
- OpReturn
- OpFunctionEnd
- )";
- SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true);
- }
- TEST_F(UpgradeMemoryModelTest,
- TessellationControlBarrierAddOutputDifferentFunctions) {
- const std::string text = R"(
- ; CHECK: [[workgroup:%\w+]] = OpConstant {{%\w+}} 2
- ; CHECK: [[output:%\w+]] = OpConstant {{%\w+}} 4096
- ; CHECK: OpControlBarrier [[workgroup]] [[workgroup]] [[output]]
- OpCapability Tessellation
- OpMemoryModel Logical GLSL450
- OpEntryPoint TessellationControl %func "func" %var
- %void = OpTypeVoid
- %int = OpTypeInt 32 0
- %none = OpConstant %int 0
- %workgroup = OpConstant %int 2
- %ptr_int_Output = OpTypePointer Output %int
- %var = OpVariable %ptr_int_Output Output
- %func_ty = OpTypeFunction %void
- %ld_func_ty = OpTypeFunction %int
- %st_func_ty = OpTypeFunction %void %int
- %func = OpFunction %void None %func_ty
- %1 = OpLabel
- %call_ld = OpFunctionCall %int %ld_func
- %call_barrier = OpFunctionCall %void %barrier_func
- %call_st = OpFunctionCall %void %st_func %call_ld
- OpReturn
- OpFunctionEnd
- %ld_func = OpFunction %int None %ld_func_ty
- %2 = OpLabel
- %ld = OpLoad %int %var
- OpReturnValue %ld
- OpFunctionEnd
- %barrier_func = OpFunction %void None %func_ty
- %3 = OpLabel
- OpControlBarrier %workgroup %workgroup %none
- OpReturn
- OpFunctionEnd
- %st_func = OpFunction %void None %st_func_ty
- %param = OpFunctionParameter %int
- %4 = OpLabel
- OpStore %var %param
- OpReturn
- OpFunctionEnd
- )";
- SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true);
- }
- TEST_F(UpgradeMemoryModelTest, ChangeControlBarrierMemoryScope) {
- std::string text = R"(
- ; CHECK: [[workgroup:%\w+]] = OpConstant {{%\w+}} 2
- ; CHECK: [[queuefamily:%\w+]] = OpConstant {{%\w+}} 5
- ; CHECK: OpControlBarrier [[workgroup]] [[queuefamily]]
- OpCapability Shader
- OpMemoryModel Logical GLSL450
- OpEntryPoint GLCompute %func "func"
- %void = OpTypeVoid
- %int = OpTypeInt 32 0
- %none = OpConstant %int 0
- %device = OpConstant %int 1
- %workgroup = OpConstant %int 2
- %func_ty = OpTypeFunction %void
- %func = OpFunction %void None %func_ty
- %1 = OpLabel
- OpControlBarrier %workgroup %device %none
- OpReturn
- OpFunctionEnd
- )";
- SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true);
- }
- TEST_F(UpgradeMemoryModelTest, ChangeMemoryBarrierMemoryScope) {
- std::string text = R"(
- ; CHECK: [[queuefamily:%\w+]] = OpConstant {{%\w+}} 5
- ; CHECK: OpMemoryBarrier [[queuefamily]]
- OpCapability Shader
- OpMemoryModel Logical GLSL450
- OpEntryPoint GLCompute %func "func"
- %void = OpTypeVoid
- %int = OpTypeInt 32 0
- %none = OpConstant %int 0
- %device = OpConstant %int 1
- %func_ty = OpTypeFunction %void
- %func = OpFunction %void None %func_ty
- %1 = OpLabel
- OpMemoryBarrier %device %none
- OpReturn
- OpFunctionEnd
- )";
- SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true);
- }
- TEST_F(UpgradeMemoryModelTest, ChangeAtomicMemoryScope) {
- std::string text = R"(
- ; CHECK: [[int:%\w+]] = OpTypeInt
- ; CHECK: [[var:%\w+]] = OpVariable
- ; CHECK: [[qf:%\w+]] = OpConstant [[int]] 5
- ; CHECK: OpAtomicLoad [[int]] [[var]] [[qf]]
- ; CHECK: OpAtomicStore [[var]] [[qf]]
- ; CHECK: OpAtomicExchange [[int]] [[var]] [[qf]]
- ; CHECK: OpAtomicCompareExchange [[int]] [[var]] [[qf]]
- ; CHECK: OpAtomicIIncrement [[int]] [[var]] [[qf]]
- ; CHECK: OpAtomicIDecrement [[int]] [[var]] [[qf]]
- ; CHECK: OpAtomicIAdd [[int]] [[var]] [[qf]]
- ; CHECK: OpAtomicISub [[int]] [[var]] [[qf]]
- ; CHECK: OpAtomicSMin [[int]] [[var]] [[qf]]
- ; CHECK: OpAtomicSMax [[int]] [[var]] [[qf]]
- ; CHECK: OpAtomicUMin [[int]] [[var]] [[qf]]
- ; CHECK: OpAtomicUMax [[int]] [[var]] [[qf]]
- ; CHECK: OpAtomicAnd [[int]] [[var]] [[qf]]
- ; CHECK: OpAtomicOr [[int]] [[var]] [[qf]]
- ; CHECK: OpAtomicXor [[int]] [[var]] [[qf]]
- OpCapability Shader
- OpExtension "SPV_KHR_storage_buffer_storage_class"
- OpMemoryModel Logical GLSL450
- OpEntryPoint GLCompute %func "func"
- %void = OpTypeVoid
- %int = OpTypeInt 32 0
- %none = OpConstant %int 0
- %device = OpConstant %int 1
- %func_ty = OpTypeFunction %void
- %ptr_int_StorageBuffer = OpTypePointer StorageBuffer %int
- %var = OpVariable %ptr_int_StorageBuffer StorageBuffer
- %func = OpFunction %void None %func_ty
- %1 = OpLabel
- %ld = OpAtomicLoad %int %var %device %none
- OpAtomicStore %var %device %none %ld
- %ex = OpAtomicExchange %int %var %device %none %ld
- %cmp_ex = OpAtomicCompareExchange %int %var %device %none %none %ld %ld
- %inc = OpAtomicIIncrement %int %var %device %none
- %dec = OpAtomicIDecrement %int %var %device %none
- %add = OpAtomicIAdd %int %var %device %none %ld
- %sub = OpAtomicISub %int %var %device %none %ld
- %smin = OpAtomicSMin %int %var %device %none %ld
- %smax = OpAtomicSMax %int %var %device %none %ld
- %umin = OpAtomicUMin %int %var %device %none %ld
- %umax = OpAtomicUMax %int %var %device %none %ld
- %and = OpAtomicAnd %int %var %device %none %ld
- %or = OpAtomicOr %int %var %device %none %ld
- %xor = OpAtomicXor %int %var %device %none %ld
- OpReturn
- OpFunctionEnd
- )";
- SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true);
- }
- TEST_F(UpgradeMemoryModelTest, UpgradeModfNoFlags) {
- const std::string text = R"(
- ; CHECK: [[float:%\w+]] = OpTypeFloat 32
- ; CHECK: [[float_0:%\w+]] = OpConstant [[float]] 0
- ; CHECK: [[ptr:%\w+]] = OpTypePointer StorageBuffer [[float]]
- ; CHECK: [[var:%\w+]] = OpVariable [[ptr]] StorageBuffer
- ; CHECK: [[struct:%\w+]] = OpTypeStruct [[float]] [[float]]
- ; CHECK: [[modfstruct:%\w+]] = OpExtInst [[struct]] {{%\w+}} ModfStruct [[float_0]]
- ; CHECK: [[ex0:%\w+]] = OpCompositeExtract [[float]] [[modfstruct]] 0
- ; CHECK: [[ex1:%\w+]] = OpCompositeExtract [[float]] [[modfstruct]] 1
- ; CHECK: OpStore [[var]] [[ex1]]
- ; CHECK-NOT: NonPrivatePointerKHR
- ; CHECK: OpFAdd [[float]] [[float_0]] [[ex0]]
- OpCapability Shader
- OpMemoryModel Logical GLSL450
- %import = OpExtInstImport "GLSL.std.450"
- OpEntryPoint GLCompute %func "func"
- %void = OpTypeVoid
- %float = OpTypeFloat 32
- %float_0 = OpConstant %float 0
- %ptr_ssbo_float = OpTypePointer StorageBuffer %float
- %ssbo_var = OpVariable %ptr_ssbo_float StorageBuffer
- %func_ty = OpTypeFunction %void
- %func = OpFunction %void None %func_ty
- %1 = OpLabel
- %2 = OpExtInst %float %import Modf %float_0 %ssbo_var
- %3 = OpFAdd %float %float_0 %2
- OpReturn
- OpFunctionEnd
- )";
- SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true);
- }
- TEST_F(UpgradeMemoryModelTest, UpgradeModfWorkgroupCoherent) {
- const std::string text = R"(
- ; CHECK: [[float:%\w+]] = OpTypeFloat 32
- ; CHECK: [[float_0:%\w+]] = OpConstant [[float]] 0
- ; CHECK: [[ptr:%\w+]] = OpTypePointer Workgroup [[float]]
- ; CHECK: [[var:%\w+]] = OpVariable [[ptr]] Workgroup
- ; CHECK: [[struct:%\w+]] = OpTypeStruct [[float]] [[float]]
- ; CHECK: [[wg_scope:%\w+]] = OpConstant {{%\w+}} 2
- ; CHECK: [[modfstruct:%\w+]] = OpExtInst [[struct]] {{%\w+}} ModfStruct [[float_0]]
- ; CHECK: [[ex0:%\w+]] = OpCompositeExtract [[float]] [[modfstruct]] 0
- ; CHECK: [[ex1:%\w+]] = OpCompositeExtract [[float]] [[modfstruct]] 1
- ; CHECK: OpStore [[var]] [[ex1]] MakePointerAvailableKHR|NonPrivatePointerKHR [[wg_scope]]
- ; CHECK: OpFAdd [[float]] [[float_0]] [[ex0]]
- OpCapability Shader
- OpMemoryModel Logical GLSL450
- %import = OpExtInstImport "GLSL.std.450"
- OpEntryPoint GLCompute %func "func"
- OpDecorate %wg_var Coherent
- %void = OpTypeVoid
- %float = OpTypeFloat 32
- %float_0 = OpConstant %float 0
- %ptr_wg_float = OpTypePointer Workgroup %float
- %wg_var = OpVariable %ptr_wg_float Workgroup
- %func_ty = OpTypeFunction %void
- %func = OpFunction %void None %func_ty
- %1 = OpLabel
- %2 = OpExtInst %float %import Modf %float_0 %wg_var
- %3 = OpFAdd %float %float_0 %2
- OpReturn
- OpFunctionEnd
- )";
- SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true);
- }
- TEST_F(UpgradeMemoryModelTest, UpgradeModfSSBOCoherent) {
- const std::string text = R"(
- ; CHECK: [[float:%\w+]] = OpTypeFloat 32
- ; CHECK: [[float_0:%\w+]] = OpConstant [[float]] 0
- ; CHECK: [[ptr:%\w+]] = OpTypePointer StorageBuffer [[float]]
- ; CHECK: [[var:%\w+]] = OpVariable [[ptr]] StorageBuffer
- ; CHECK: [[struct:%\w+]] = OpTypeStruct [[float]] [[float]]
- ; CHECK: [[qf_scope:%\w+]] = OpConstant {{%\w+}} 5
- ; CHECK: [[modfstruct:%\w+]] = OpExtInst [[struct]] {{%\w+}} ModfStruct [[float_0]]
- ; CHECK: [[ex0:%\w+]] = OpCompositeExtract [[float]] [[modfstruct]] 0
- ; CHECK: [[ex1:%\w+]] = OpCompositeExtract [[float]] [[modfstruct]] 1
- ; CHECK: OpStore [[var]] [[ex1]] MakePointerAvailableKHR|NonPrivatePointerKHR [[qf_scope]]
- ; CHECK: OpFAdd [[float]] [[float_0]] [[ex0]]
- OpCapability Shader
- OpMemoryModel Logical GLSL450
- %import = OpExtInstImport "GLSL.std.450"
- OpEntryPoint GLCompute %func "func"
- OpDecorate %ssbo_var Coherent
- %void = OpTypeVoid
- %float = OpTypeFloat 32
- %float_0 = OpConstant %float 0
- %ptr_ssbo_float = OpTypePointer StorageBuffer %float
- %ssbo_var = OpVariable %ptr_ssbo_float StorageBuffer
- %func_ty = OpTypeFunction %void
- %func = OpFunction %void None %func_ty
- %1 = OpLabel
- %2 = OpExtInst %float %import Modf %float_0 %ssbo_var
- %3 = OpFAdd %float %float_0 %2
- OpReturn
- OpFunctionEnd
- )";
- SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true);
- }
- TEST_F(UpgradeMemoryModelTest, UpgradeModfSSBOVolatile) {
- const std::string text = R"(
- ; CHECK: [[float:%\w+]] = OpTypeFloat 32
- ; CHECK: [[float_0:%\w+]] = OpConstant [[float]] 0
- ; CHECK: [[ptr:%\w+]] = OpTypePointer StorageBuffer [[float]]
- ; CHECK: [[var:%\w+]] = OpVariable [[ptr]] StorageBuffer
- ; CHECK: [[struct:%\w+]] = OpTypeStruct [[float]] [[float]]
- ; CHECK: [[modfstruct:%\w+]] = OpExtInst [[struct]] {{%\w+}} ModfStruct [[float_0]]
- ; CHECK: [[ex0:%\w+]] = OpCompositeExtract [[float]] [[modfstruct]] 0
- ; CHECK: [[ex1:%\w+]] = OpCompositeExtract [[float]] [[modfstruct]] 1
- ; CHECK: OpStore [[var]] [[ex1]] Volatile
- ; CHECK: OpFAdd [[float]] [[float_0]] [[ex0]]
- OpCapability Shader
- OpMemoryModel Logical GLSL450
- %import = OpExtInstImport "GLSL.std.450"
- OpEntryPoint GLCompute %func "func"
- OpDecorate %wg_var Volatile
- %void = OpTypeVoid
- %float = OpTypeFloat 32
- %float_0 = OpConstant %float 0
- %ptr_ssbo_float = OpTypePointer StorageBuffer %float
- %wg_var = OpVariable %ptr_ssbo_float StorageBuffer
- %func_ty = OpTypeFunction %void
- %func = OpFunction %void None %func_ty
- %1 = OpLabel
- %2 = OpExtInst %float %import Modf %float_0 %wg_var
- %3 = OpFAdd %float %float_0 %2
- OpReturn
- OpFunctionEnd
- )";
- SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true);
- }
- TEST_F(UpgradeMemoryModelTest, UpgradeFrexpNoFlags) {
- const std::string text = R"(
- ; CHECK: [[float:%\w+]] = OpTypeFloat 32
- ; CHECK: [[float_0:%\w+]] = OpConstant [[float]] 0
- ; CHECK: [[int:%\w+]] = OpTypeInt 32 0
- ; CHECK: [[ptr:%\w+]] = OpTypePointer StorageBuffer [[int]]
- ; CHECK: [[var:%\w+]] = OpVariable [[ptr]] StorageBuffer
- ; CHECK: [[struct:%\w+]] = OpTypeStruct [[float]] [[int]]
- ; CHECK: [[modfstruct:%\w+]] = OpExtInst [[struct]] {{%\w+}} FrexpStruct [[float_0]]
- ; CHECK: [[ex0:%\w+]] = OpCompositeExtract [[float]] [[modfstruct]] 0
- ; CHECK: [[ex1:%\w+]] = OpCompositeExtract [[int]] [[modfstruct]] 1
- ; CHECK: OpStore [[var]] [[ex1]]
- ; CHECK-NOT: NonPrivatePointerKHR
- ; CHECK: OpFAdd [[float]] [[float_0]] [[ex0]]
- OpCapability Shader
- OpMemoryModel Logical GLSL450
- %import = OpExtInstImport "GLSL.std.450"
- OpEntryPoint GLCompute %func "func"
- %void = OpTypeVoid
- %float = OpTypeFloat 32
- %float_0 = OpConstant %float 0
- %int = OpTypeInt 32 0
- %ptr_ssbo_int = OpTypePointer StorageBuffer %int
- %ssbo_var = OpVariable %ptr_ssbo_int StorageBuffer
- %func_ty = OpTypeFunction %void
- %func = OpFunction %void None %func_ty
- %1 = OpLabel
- %2 = OpExtInst %float %import Frexp %float_0 %ssbo_var
- %3 = OpFAdd %float %float_0 %2
- OpReturn
- OpFunctionEnd
- )";
- SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true);
- }
- TEST_F(UpgradeMemoryModelTest, UpgradeFrexpWorkgroupCoherent) {
- const std::string text = R"(
- ; CHECK: [[float:%\w+]] = OpTypeFloat 32
- ; CHECK: [[float_0:%\w+]] = OpConstant [[float]] 0
- ; CHECK: [[int:%\w+]] = OpTypeInt 32 0
- ; CHECK: [[ptr:%\w+]] = OpTypePointer Workgroup [[int]]
- ; CHECK: [[var:%\w+]] = OpVariable [[ptr]] Workgroup
- ; CHECK: [[struct:%\w+]] = OpTypeStruct [[float]] [[int]]
- ; CHECK: [[wg_scope:%\w+]] = OpConstant {{%\w+}} 2
- ; CHECK: [[modfstruct:%\w+]] = OpExtInst [[struct]] {{%\w+}} FrexpStruct [[float_0]]
- ; CHECK: [[ex0:%\w+]] = OpCompositeExtract [[float]] [[modfstruct]] 0
- ; CHECK: [[ex1:%\w+]] = OpCompositeExtract [[int]] [[modfstruct]] 1
- ; CHECK: OpStore [[var]] [[ex1]] MakePointerAvailableKHR|NonPrivatePointerKHR [[wg_scope]]
- ; CHECK: OpFAdd [[float]] [[float_0]] [[ex0]]
- OpCapability Shader
- OpMemoryModel Logical GLSL450
- %import = OpExtInstImport "GLSL.std.450"
- OpEntryPoint GLCompute %func "func"
- OpDecorate %wg_var Coherent
- %void = OpTypeVoid
- %float = OpTypeFloat 32
- %float_0 = OpConstant %float 0
- %int = OpTypeInt 32 0
- %ptr_wg_int = OpTypePointer Workgroup %int
- %wg_var = OpVariable %ptr_wg_int Workgroup
- %func_ty = OpTypeFunction %void
- %func = OpFunction %void None %func_ty
- %1 = OpLabel
- %2 = OpExtInst %float %import Frexp %float_0 %wg_var
- %3 = OpFAdd %float %float_0 %2
- OpReturn
- OpFunctionEnd
- )";
- SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true);
- }
- TEST_F(UpgradeMemoryModelTest, UpgradeFrexpSSBOCoherent) {
- const std::string text = R"(
- ; CHECK: [[float:%\w+]] = OpTypeFloat 32
- ; CHECK: [[float_0:%\w+]] = OpConstant [[float]] 0
- ; CHECK: [[int:%\w+]] = OpTypeInt 32 0
- ; CHECK: [[ptr:%\w+]] = OpTypePointer StorageBuffer [[int]]
- ; CHECK: [[var:%\w+]] = OpVariable [[ptr]] StorageBuffer
- ; CHECK: [[struct:%\w+]] = OpTypeStruct [[float]] [[int]]
- ; CHECK: [[qf_scope:%\w+]] = OpConstant {{%\w+}} 5
- ; CHECK: [[modfstruct:%\w+]] = OpExtInst [[struct]] {{%\w+}} FrexpStruct [[float_0]]
- ; CHECK: [[ex0:%\w+]] = OpCompositeExtract [[float]] [[modfstruct]] 0
- ; CHECK: [[ex1:%\w+]] = OpCompositeExtract [[int]] [[modfstruct]] 1
- ; CHECK: OpStore [[var]] [[ex1]] MakePointerAvailableKHR|NonPrivatePointerKHR [[qf_scope]]
- ; CHECK: OpFAdd [[float]] [[float_0]] [[ex0]]
- OpCapability Shader
- OpMemoryModel Logical GLSL450
- %import = OpExtInstImport "GLSL.std.450"
- OpEntryPoint GLCompute %func "func"
- OpDecorate %ssbo_var Coherent
- %void = OpTypeVoid
- %float = OpTypeFloat 32
- %float_0 = OpConstant %float 0
- %int = OpTypeInt 32 0
- %ptr_ssbo_int = OpTypePointer StorageBuffer %int
- %ssbo_var = OpVariable %ptr_ssbo_int StorageBuffer
- %func_ty = OpTypeFunction %void
- %func = OpFunction %void None %func_ty
- %1 = OpLabel
- %2 = OpExtInst %float %import Frexp %float_0 %ssbo_var
- %3 = OpFAdd %float %float_0 %2
- OpReturn
- OpFunctionEnd
- )";
- SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true);
- }
- TEST_F(UpgradeMemoryModelTest, UpgradeFrexpSSBOVolatile) {
- const std::string text = R"(
- ; CHECK: [[float:%\w+]] = OpTypeFloat 32
- ; CHECK: [[float_0:%\w+]] = OpConstant [[float]] 0
- ; CHECK: [[int:%\w+]] = OpTypeInt 32 0
- ; CHECK: [[ptr:%\w+]] = OpTypePointer StorageBuffer [[int]]
- ; CHECK: [[var:%\w+]] = OpVariable [[ptr]] StorageBuffer
- ; CHECK: [[struct:%\w+]] = OpTypeStruct [[float]] [[int]]
- ; CHECK: [[modfstruct:%\w+]] = OpExtInst [[struct]] {{%\w+}} FrexpStruct [[float_0]]
- ; CHECK: [[ex0:%\w+]] = OpCompositeExtract [[float]] [[modfstruct]] 0
- ; CHECK: [[ex1:%\w+]] = OpCompositeExtract [[int]] [[modfstruct]] 1
- ; CHECK: OpStore [[var]] [[ex1]] Volatile
- ; CHECK: OpFAdd [[float]] [[float_0]] [[ex0]]
- OpCapability Shader
- OpMemoryModel Logical GLSL450
- %import = OpExtInstImport "GLSL.std.450"
- OpEntryPoint GLCompute %func "func"
- OpDecorate %wg_var Volatile
- %void = OpTypeVoid
- %float = OpTypeFloat 32
- %float_0 = OpConstant %float 0
- %int = OpTypeInt 32 0
- %ptr_ssbo_int = OpTypePointer StorageBuffer %int
- %wg_var = OpVariable %ptr_ssbo_int StorageBuffer
- %func_ty = OpTypeFunction %void
- %func = OpFunction %void None %func_ty
- %1 = OpLabel
- %2 = OpExtInst %float %import Frexp %float_0 %wg_var
- %3 = OpFAdd %float %float_0 %2
- OpReturn
- OpFunctionEnd
- )";
- SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true);
- }
- } // namespace
|