Path: blob/21.2-virgl/src/compiler/spirv/tests/volatile.cpp
4547 views
/*1* Copyright © 2020 Valve Corporation2*3* Permission is hereby granted, free of charge, to any person obtaining a4* copy of this software and associated documentation files (the "Software"),5* to deal in the Software without restriction, including without limitation6* the rights to use, copy, modify, merge, publish, distribute, sublicense,7* and/or sell copies of the Software, and to permit persons to whom the8* Software is furnished to do so, subject to the following conditions:9*10* The above copyright notice and this permission notice (including the next11* paragraph) shall be included in all copies or substantial portions of the12* Software.13*14* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR15* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,16* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL17* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER18* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING19* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS20* IN THE SOFTWARE.21*/22#include "helpers.h"2324TEST_F(spirv_test, opload_volatile)25{26/*27OpCapability Shader28%1 = OpExtInstImport "GLSL.std.450"29OpMemoryModel Logical GLSL45030OpEntryPoint GLCompute %4 "main"31OpExecutionMode %4 LocalSize 1 1 132OpMemberDecorate %_struct_7 0 Offset 033OpDecorate %_struct_7 BufferBlock34OpDecorate %9 DescriptorSet 035OpDecorate %9 Binding 036%void = OpTypeVoid37%3 = OpTypeFunction %void38%uint = OpTypeInt 32 039%_struct_7 = OpTypeStruct %uint40%_ptr_Uniform__struct_7 = OpTypePointer Uniform %_struct_741%9 = OpVariable %_ptr_Uniform__struct_7 Uniform42%int = OpTypeInt 32 143%int_0 = OpConstant %int 044%_ptr_Uniform_uint = OpTypePointer Uniform %uint45%4 = OpFunction %void None %346%5 = OpLabel47%13 = OpAccessChain %_ptr_Uniform_uint %9 %int_048%14 = OpLoad %uint %13 Volatile49OpStore %13 %1450OpReturn51OpFunctionEnd52*/53static const uint32_t words[] = {540x07230203, 0x00010300, 0x00070000, 0x0000000f, 0x00000000, 0x00020011,550x00000001, 0x0006000b, 0x00000001, 0x4c534c47, 0x6474732e, 0x3035342e,560x00000000, 0x0003000e, 0x00000000, 0x00000001, 0x0005000f, 0x00000005,570x00000002, 0x6e69616d, 0x00000000, 0x00060010, 0x00000002, 0x00000011,580x00000001, 0x00000001, 0x00000001, 0x00050048, 0x00000003, 0x00000000,590x00000023, 0x00000000, 0x00030047, 0x00000003, 0x00000003, 0x00040047,600x00000004, 0x00000022, 0x00000000, 0x00040047, 0x00000004, 0x00000021,610x00000000, 0x00020013, 0x00000005, 0x00030021, 0x00000006, 0x00000005,620x00040015, 0x00000007, 0x00000020, 0x00000000, 0x0003001e, 0x00000003,630x00000007, 0x00040020, 0x00000008, 0x00000002, 0x00000003, 0x0004003b,640x00000008, 0x00000004, 0x00000002, 0x00040015, 0x00000009, 0x00000020,650x00000001, 0x0004002b, 0x00000009, 0x0000000a, 0x00000000, 0x00040020,660x0000000b, 0x00000002, 0x00000007, 0x00050036, 0x00000005, 0x00000002,670x00000000, 0x00000006, 0x000200f8, 0x0000000c, 0x00050041, 0x0000000b,680x0000000d, 0x00000004, 0x0000000a, 0x0005003d, 0x00000007, 0x0000000e,690x0000000d, 0x00000001, 0x0003003e, 0x0000000d, 0x0000000e, 0x000100fd,700x00010038,71};7273get_nir(sizeof(words) / sizeof(words[0]), words);7475nir_intrinsic_instr *intrinsic = find_intrinsic(nir_intrinsic_load_deref);76ASSERT_NE(intrinsic, nullptr);77EXPECT_NE(nir_intrinsic_access(intrinsic) & ACCESS_VOLATILE, 0);78}7980TEST_F(spirv_test, opstore_volatile)81{82/*83OpCapability Shader84%1 = OpExtInstImport "GLSL.std.450"85OpMemoryModel Logical GLSL45086OpEntryPoint GLCompute %4 "main"87OpExecutionMode %4 LocalSize 1 1 188OpMemberDecorate %_struct_7 0 Offset 089OpDecorate %_struct_7 BufferBlock90OpDecorate %9 DescriptorSet 091OpDecorate %9 Binding 092%void = OpTypeVoid93%3 = OpTypeFunction %void94%uint = OpTypeInt 32 095%_struct_7 = OpTypeStruct %uint96%_ptr_Uniform__struct_7 = OpTypePointer Uniform %_struct_797%9 = OpVariable %_ptr_Uniform__struct_7 Uniform98%int = OpTypeInt 32 199%int_0 = OpConstant %int 0100%_ptr_Uniform_uint = OpTypePointer Uniform %uint101%4 = OpFunction %void None %3102%5 = OpLabel103%13 = OpAccessChain %_ptr_Uniform_uint %9 %int_0104%14 = OpLoad %uint %13105OpStore %13 %14 Volatile106OpReturn107OpFunctionEnd108*/109static const uint32_t words[] = {1100x07230203, 0x00010300, 0x00070000, 0x0000000f, 0x00000000, 0x00020011,1110x00000001, 0x0006000b, 0x00000001, 0x4c534c47, 0x6474732e, 0x3035342e,1120x00000000, 0x0003000e, 0x00000000, 0x00000001, 0x0005000f, 0x00000005,1130x00000002, 0x6e69616d, 0x00000000, 0x00060010, 0x00000002, 0x00000011,1140x00000001, 0x00000001, 0x00000001, 0x00050048, 0x00000003, 0x00000000,1150x00000023, 0x00000000, 0x00030047, 0x00000003, 0x00000003, 0x00040047,1160x00000004, 0x00000022, 0x00000000, 0x00040047, 0x00000004, 0x00000021,1170x00000000, 0x00020013, 0x00000005, 0x00030021, 0x00000006, 0x00000005,1180x00040015, 0x00000007, 0x00000020, 0x00000000, 0x0003001e, 0x00000003,1190x00000007, 0x00040020, 0x00000008, 0x00000002, 0x00000003, 0x0004003b,1200x00000008, 0x00000004, 0x00000002, 0x00040015, 0x00000009, 0x00000020,1210x00000001, 0x0004002b, 0x00000009, 0x0000000a, 0x00000000, 0x00040020,1220x0000000b, 0x00000002, 0x00000007, 0x00050036, 0x00000005, 0x00000002,1230x00000000, 0x00000006, 0x000200f8, 0x0000000c, 0x00050041, 0x0000000b,1240x0000000d, 0x00000004, 0x0000000a, 0x0004003d, 0x00000007, 0x0000000e,1250x0000000d, 0x0004003e, 0x0000000d, 0x0000000e, 0x00000001, 0x000100fd,1260x00010038,127};128129get_nir(sizeof(words) / sizeof(words[0]), words);130131nir_intrinsic_instr *intrinsic = find_intrinsic(nir_intrinsic_store_deref);132ASSERT_NE(intrinsic, nullptr);133EXPECT_NE(nir_intrinsic_access(intrinsic) & ACCESS_VOLATILE, 0);134}135136TEST_F(spirv_test, opcopymemory_volatile_both)137{138/*139OpCapability Shader140%1 = OpExtInstImport "GLSL.std.450"141OpMemoryModel Logical GLSL450142OpEntryPoint GLCompute %4 "main"143OpExecutionMode %4 LocalSize 1 1 1144OpMemberDecorate %_struct_7 0 Offset 0145OpDecorate %_struct_7 BufferBlock146OpDecorate %9 DescriptorSet 0147OpDecorate %9 Binding 0148%void = OpTypeVoid149%3 = OpTypeFunction %void150%uint = OpTypeInt 32 0151%_struct_7 = OpTypeStruct %uint152%_ptr_Uniform__struct_7 = OpTypePointer Uniform %_struct_7153%9 = OpVariable %_ptr_Uniform__struct_7 Uniform154%int = OpTypeInt 32 1155%int_0 = OpConstant %int 0156%_ptr_Uniform_uint = OpTypePointer Uniform %uint157%4 = OpFunction %void None %3158%5 = OpLabel159%13 = OpAccessChain %_ptr_Uniform_uint %9 %int_0160OpCopyMemory %13 %13 Volatile161OpReturn162OpFunctionEnd163*/164static const uint32_t words[] = {1650x07230203, 0x00010300, 0x00070000, 0x0000000e, 0x00000000, 0x00020011,1660x00000001, 0x0006000b, 0x00000001, 0x4c534c47, 0x6474732e, 0x3035342e,1670x00000000, 0x0003000e, 0x00000000, 0x00000001, 0x0005000f, 0x00000005,1680x00000002, 0x6e69616d, 0x00000000, 0x00060010, 0x00000002, 0x00000011,1690x00000001, 0x00000001, 0x00000001, 0x00050048, 0x00000003, 0x00000000,1700x00000023, 0x00000000, 0x00030047, 0x00000003, 0x00000003, 0x00040047,1710x00000004, 0x00000022, 0x00000000, 0x00040047, 0x00000004, 0x00000021,1720x00000000, 0x00020013, 0x00000005, 0x00030021, 0x00000006, 0x00000005,1730x00040015, 0x00000007, 0x00000020, 0x00000000, 0x0003001e, 0x00000003,1740x00000007, 0x00040020, 0x00000008, 0x00000002, 0x00000003, 0x0004003b,1750x00000008, 0x00000004, 0x00000002, 0x00040015, 0x00000009, 0x00000020,1760x00000001, 0x0004002b, 0x00000009, 0x0000000a, 0x00000000, 0x00040020,1770x0000000b, 0x00000002, 0x00000007, 0x00050036, 0x00000005, 0x00000002,1780x00000000, 0x00000006, 0x000200f8, 0x0000000c, 0x00050041, 0x0000000b,1790x0000000d, 0x00000004, 0x0000000a, 0x0004003f, 0x0000000d, 0x0000000d,1800x00000001, 0x000100fd, 0x00010038,181};182183get_nir(sizeof(words) / sizeof(words[0]), words);184185nir_intrinsic_instr *intrinsic = find_intrinsic(nir_intrinsic_load_deref);186ASSERT_NE(intrinsic, nullptr);187EXPECT_NE(nir_intrinsic_access(intrinsic) & ACCESS_VOLATILE, 0);188189intrinsic = find_intrinsic(nir_intrinsic_store_deref);190ASSERT_NE(intrinsic, nullptr);191EXPECT_NE(nir_intrinsic_access(intrinsic) & ACCESS_VOLATILE, 0);192}193194TEST_F(spirv_test, opcopymemory_volatile_target)195{196/*197OpCapability Shader198%1 = OpExtInstImport "GLSL.std.450"199OpMemoryModel Logical GLSL450200OpEntryPoint GLCompute %4 "main" %9201OpExecutionMode %4 LocalSize 1 1 1202OpMemberDecorate %_struct_7 0 Offset 0203OpDecorate %_struct_7 Block204OpDecorate %9 DescriptorSet 0205OpDecorate %9 Binding 0206%void = OpTypeVoid207%3 = OpTypeFunction %void208%uint = OpTypeInt 32 0209%_struct_7 = OpTypeStruct %uint210%_ptr_StorageBuffer__struct_7 = OpTypePointer StorageBuffer %_struct_7211%9 = OpVariable %_ptr_StorageBuffer__struct_7 StorageBuffer212%int = OpTypeInt 32 1213%int_0 = OpConstant %int 0214%_ptr_StorageBuffer_uint = OpTypePointer StorageBuffer %uint215%4 = OpFunction %void None %3216%5 = OpLabel217%13 = OpAccessChain %_ptr_StorageBuffer_uint %9 %int_0218OpCopyMemory %13 %13 Volatile None219OpReturn220OpFunctionEnd221*/222static const uint32_t words[] = {2230x07230203, 0x00010500, 0x00070000, 0x0000000e, 0x00000000, 0x00020011,2240x00000001, 0x0006000b, 0x00000001, 0x4c534c47, 0x6474732e, 0x3035342e,2250x00000000, 0x0003000e, 0x00000000, 0x00000001, 0x0006000f, 0x00000005,2260x00000002, 0x6e69616d, 0x00000000, 0x00000003, 0x00060010, 0x00000002,2270x00000011, 0x00000001, 0x00000001, 0x00000001, 0x00050048, 0x00000004,2280x00000000, 0x00000023, 0x00000000, 0x00030047, 0x00000004, 0x00000002,2290x00040047, 0x00000003, 0x00000022, 0x00000000, 0x00040047, 0x00000003,2300x00000021, 0x00000000, 0x00020013, 0x00000005, 0x00030021, 0x00000006,2310x00000005, 0x00040015, 0x00000007, 0x00000020, 0x00000000, 0x0003001e,2320x00000004, 0x00000007, 0x00040020, 0x00000008, 0x0000000c, 0x00000004,2330x0004003b, 0x00000008, 0x00000003, 0x0000000c, 0x00040015, 0x00000009,2340x00000020, 0x00000001, 0x0004002b, 0x00000009, 0x0000000a, 0x00000000,2350x00040020, 0x0000000b, 0x0000000c, 0x00000007, 0x00050036, 0x00000005,2360x00000002, 0x00000000, 0x00000006, 0x000200f8, 0x0000000c, 0x00050041,2370x0000000b, 0x0000000d, 0x00000003, 0x0000000a, 0x0005003f, 0x0000000d,2380x0000000d, 0x00000001, 0x00000000, 0x000100fd, 0x00010038,239};240241get_nir(sizeof(words) / sizeof(words[0]), words);242243nir_intrinsic_instr *intrinsic = find_intrinsic(nir_intrinsic_load_deref);244ASSERT_NE(intrinsic, nullptr);245EXPECT_EQ(nir_intrinsic_access(intrinsic) & ACCESS_VOLATILE, 0);246247intrinsic = find_intrinsic(nir_intrinsic_store_deref);248ASSERT_NE(intrinsic, nullptr);249EXPECT_NE(nir_intrinsic_access(intrinsic) & ACCESS_VOLATILE, 0);250}251252TEST_F(spirv_test, opcopymemory_volatile_source)253{254/*255OpCapability Shader256%1 = OpExtInstImport "GLSL.std.450"257OpMemoryModel Logical GLSL450258OpEntryPoint GLCompute %4 "main" %9259OpExecutionMode %4 LocalSize 1 1 1260OpMemberDecorate %_struct_7 0 Offset 0261OpDecorate %_struct_7 Block262OpDecorate %9 DescriptorSet 0263OpDecorate %9 Binding 0264%void = OpTypeVoid265%3 = OpTypeFunction %void266%uint = OpTypeInt 32 0267%_struct_7 = OpTypeStruct %uint268%_ptr_StorageBuffer__struct_7 = OpTypePointer StorageBuffer %_struct_7269%9 = OpVariable %_ptr_StorageBuffer__struct_7 StorageBuffer270%int = OpTypeInt 32 1271%int_0 = OpConstant %int 0272%_ptr_StorageBuffer_uint = OpTypePointer StorageBuffer %uint273%4 = OpFunction %void None %3274%5 = OpLabel275%13 = OpAccessChain %_ptr_StorageBuffer_uint %9 %int_0276OpCopyMemory %13 %13 None Volatile277OpReturn278OpFunctionEnd279*/280static const uint32_t words[] = {2810x07230203, 0x00010500, 0x00070000, 0x0000000e, 0x00000000, 0x00020011,2820x00000001, 0x0006000b, 0x00000001, 0x4c534c47, 0x6474732e, 0x3035342e,2830x00000000, 0x0003000e, 0x00000000, 0x00000001, 0x0006000f, 0x00000005,2840x00000002, 0x6e69616d, 0x00000000, 0x00000003, 0x00060010, 0x00000002,2850x00000011, 0x00000001, 0x00000001, 0x00000001, 0x00050048, 0x00000004,2860x00000000, 0x00000023, 0x00000000, 0x00030047, 0x00000004, 0x00000002,2870x00040047, 0x00000003, 0x00000022, 0x00000000, 0x00040047, 0x00000003,2880x00000021, 0x00000000, 0x00020013, 0x00000005, 0x00030021, 0x00000006,2890x00000005, 0x00040015, 0x00000007, 0x00000020, 0x00000000, 0x0003001e,2900x00000004, 0x00000007, 0x00040020, 0x00000008, 0x0000000c, 0x00000004,2910x0004003b, 0x00000008, 0x00000003, 0x0000000c, 0x00040015, 0x00000009,2920x00000020, 0x00000001, 0x0004002b, 0x00000009, 0x0000000a, 0x00000000,2930x00040020, 0x0000000b, 0x0000000c, 0x00000007, 0x00050036, 0x00000005,2940x00000002, 0x00000000, 0x00000006, 0x000200f8, 0x0000000c, 0x00050041,2950x0000000b, 0x0000000d, 0x00000003, 0x0000000a, 0x0005003f, 0x0000000d,2960x0000000d, 0x00000000, 0x00000001, 0x000100fd, 0x00010038,297};298299get_nir(sizeof(words) / sizeof(words[0]), words);300301nir_intrinsic_instr *intrinsic = find_intrinsic(nir_intrinsic_load_deref);302ASSERT_NE(intrinsic, nullptr);303EXPECT_NE(nir_intrinsic_access(intrinsic) & ACCESS_VOLATILE, 0);304305intrinsic = find_intrinsic(nir_intrinsic_store_deref);306ASSERT_NE(intrinsic, nullptr);307EXPECT_EQ(nir_intrinsic_access(intrinsic) & ACCESS_VOLATILE, 0);308}309310TEST_F(spirv_test, opimageread_volatile)311{312/*313OpCapability Shader314OpCapability VulkanMemoryModel315%1 = OpExtInstImport "GLSL.std.450"316OpMemoryModel Logical Vulkan317OpEntryPoint GLCompute %4 "main" %9318OpExecutionMode %4 LocalSize 1 1 1319OpDecorate %9 DescriptorSet 0320OpDecorate %9 Binding 1321%void = OpTypeVoid322%3 = OpTypeFunction %void323%uint = OpTypeInt 32 0324%7 = OpTypeImage %uint 2D 0 0 0 2 R32ui325%_ptr_UniformConstant_7 = OpTypePointer UniformConstant %7326%9 = OpVariable %_ptr_UniformConstant_7 UniformConstant327%int = OpTypeInt 32 1328%v2int = OpTypeVector %int 2329%int_0 = OpConstant %int 0330%14 = OpConstantComposite %v2int %int_0 %int_0331%v4uint = OpTypeVector %uint 4332%v3uint = OpTypeVector %uint 3333%uint_1 = OpConstant %uint 1334%4 = OpFunction %void None %3335%5 = OpLabel336%10 = OpLoad %7 %9337%15 = OpLoad %7 %9338%17 = OpImageRead %v4uint %15 %14 VolatileTexel339OpImageWrite %10 %14 %17340OpReturn341OpFunctionEnd342*/343static const uint32_t words[] = {3440x07230203, 0x00010500, 0x00070000, 0x00000014, 0x00000000, 0x00020011,3450x00000001, 0x00020011, 0x000014e1, 0x0006000b, 0x00000001, 0x4c534c47,3460x6474732e, 0x3035342e, 0x00000000, 0x0003000e, 0x00000000, 0x00000003,3470x0006000f, 0x00000005, 0x00000002, 0x6e69616d, 0x00000000, 0x00000003,3480x00060010, 0x00000002, 0x00000011, 0x00000001, 0x00000001, 0x00000001,3490x00040047, 0x00000003, 0x00000022, 0x00000000, 0x00040047, 0x00000003,3500x00000021, 0x00000001, 0x00020013, 0x00000004, 0x00030021, 0x00000005,3510x00000004, 0x00040015, 0x00000006, 0x00000020, 0x00000000, 0x00090019,3520x00000007, 0x00000006, 0x00000001, 0x00000000, 0x00000000, 0x00000000,3530x00000002, 0x00000021, 0x00040020, 0x00000008, 0x00000000, 0x00000007,3540x0004003b, 0x00000008, 0x00000003, 0x00000000, 0x00040015, 0x00000009,3550x00000020, 0x00000001, 0x00040017, 0x0000000a, 0x00000009, 0x00000002,3560x0004002b, 0x00000009, 0x0000000b, 0x00000000, 0x0005002c, 0x0000000a,3570x0000000c, 0x0000000b, 0x0000000b, 0x00040017, 0x0000000d, 0x00000006,3580x00000004, 0x00040017, 0x0000000e, 0x00000006, 0x00000003, 0x0004002b,3590x00000006, 0x0000000f, 0x00000001, 0x00050036, 0x00000004, 0x00000002,3600x00000000, 0x00000005, 0x000200f8, 0x00000010, 0x0004003d, 0x00000007,3610x00000011, 0x00000003, 0x0004003d, 0x00000007, 0x00000012, 0x00000003,3620x00060062, 0x0000000d, 0x00000013, 0x00000012, 0x0000000c, 0x00000800,3630x00040063, 0x00000011, 0x0000000c, 0x00000013, 0x000100fd, 0x00010038,364};365366get_nir(sizeof(words) / sizeof(words[0]), words);367368nir_intrinsic_instr *intrinsic = find_intrinsic(nir_intrinsic_image_deref_load, 0);369ASSERT_NE(intrinsic, nullptr);370EXPECT_NE(nir_intrinsic_access(intrinsic) & ACCESS_VOLATILE, 0);371}372373TEST_F(spirv_test, opimagewrite_volatile)374{375/*376OpCapability Shader377OpCapability VulkanMemoryModel378%1 = OpExtInstImport "GLSL.std.450"379OpMemoryModel Logical Vulkan380OpEntryPoint GLCompute %4 "main" %9381OpExecutionMode %4 LocalSize 1 1 1382OpDecorate %9 DescriptorSet 0383OpDecorate %9 Binding 1384%void = OpTypeVoid385%3 = OpTypeFunction %void386%uint = OpTypeInt 32 0387%7 = OpTypeImage %uint 2D 0 0 0 2 R32ui388%_ptr_UniformConstant_7 = OpTypePointer UniformConstant %7389%9 = OpVariable %_ptr_UniformConstant_7 UniformConstant390%int = OpTypeInt 32 1391%v2int = OpTypeVector %int 2392%int_0 = OpConstant %int 0393%14 = OpConstantComposite %v2int %int_0 %int_0394%v4uint = OpTypeVector %uint 4395%v3uint = OpTypeVector %uint 3396%uint_1 = OpConstant %uint 1397%4 = OpFunction %void None %3398%5 = OpLabel399%10 = OpLoad %7 %9400%15 = OpLoad %7 %9401%17 = OpImageRead %v4uint %15 %14402OpImageWrite %10 %14 %17 VolatileTexel403OpReturn404OpFunctionEnd405*/406static const uint32_t words[] = {4070x07230203, 0x00010500, 0x00070000, 0x00000014, 0x00000000, 0x00020011,4080x00000001, 0x00020011, 0x000014e1, 0x0006000b, 0x00000001, 0x4c534c47,4090x6474732e, 0x3035342e, 0x00000000, 0x0003000e, 0x00000000, 0x00000003,4100x0006000f, 0x00000005, 0x00000002, 0x6e69616d, 0x00000000, 0x00000003,4110x00060010, 0x00000002, 0x00000011, 0x00000001, 0x00000001, 0x00000001,4120x00040047, 0x00000003, 0x00000022, 0x00000000, 0x00040047, 0x00000003,4130x00000021, 0x00000001, 0x00020013, 0x00000004, 0x00030021, 0x00000005,4140x00000004, 0x00040015, 0x00000006, 0x00000020, 0x00000000, 0x00090019,4150x00000007, 0x00000006, 0x00000001, 0x00000000, 0x00000000, 0x00000000,4160x00000002, 0x00000021, 0x00040020, 0x00000008, 0x00000000, 0x00000007,4170x0004003b, 0x00000008, 0x00000003, 0x00000000, 0x00040015, 0x00000009,4180x00000020, 0x00000001, 0x00040017, 0x0000000a, 0x00000009, 0x00000002,4190x0004002b, 0x00000009, 0x0000000b, 0x00000000, 0x0005002c, 0x0000000a,4200x0000000c, 0x0000000b, 0x0000000b, 0x00040017, 0x0000000d, 0x00000006,4210x00000004, 0x00040017, 0x0000000e, 0x00000006, 0x00000003, 0x0004002b,4220x00000006, 0x0000000f, 0x00000001, 0x00050036, 0x00000004, 0x00000002,4230x00000000, 0x00000005, 0x000200f8, 0x00000010, 0x0004003d, 0x00000007,4240x00000011, 0x00000003, 0x0004003d, 0x00000007, 0x00000012, 0x00000003,4250x00050062, 0x0000000d, 0x00000013, 0x00000012, 0x0000000c, 0x00050063,4260x00000011, 0x0000000c, 0x00000013, 0x00000800, 0x000100fd, 0x00010038,427};428429get_nir(sizeof(words) / sizeof(words[0]), words);430431nir_intrinsic_instr *intrinsic = find_intrinsic(nir_intrinsic_image_deref_store, 0);432ASSERT_NE(intrinsic, nullptr);433EXPECT_NE(nir_intrinsic_access(intrinsic) & ACCESS_VOLATILE, 0);434}435436TEST_F(spirv_test, opatomicload_image_volatile)437{438/*439OpCapability Shader440OpCapability VulkanMemoryModel441OpCapability VulkanMemoryModelDeviceScope442%1 = OpExtInstImport "GLSL.std.450"443OpMemoryModel Logical Vulkan444OpEntryPoint GLCompute %2 "main" %3445OpExecutionMode %2 LocalSize 1 1 1446OpDecorate %3 DescriptorSet 0447OpDecorate %3 Binding 1448%void = OpTypeVoid449%7 = OpTypeFunction %void450%uint = OpTypeInt 32 0451%10 = OpTypeImage %uint 2D 0 0 0 2 R32ui452%_ptr_UniformConstant_10 = OpTypePointer UniformConstant %10453%3 = OpVariable %_ptr_UniformConstant_10 UniformConstant454%int = OpTypeInt 32 1455%v2int = OpTypeVector %int 2456%int_0 = OpConstant %int 0457%15 = OpConstantComposite %v2int %int_0 %int_0458%int_1 = OpConstant %int 1459%uint_0 = OpConstant %uint 0460%_ptr_Image_uint = OpTypePointer Image %uint461%uint_1 = OpConstant %uint 1462%uint_2048 = OpConstant %uint 2048463%uint_34816 = OpConstant %uint 34816464%v3uint = OpTypeVector %uint 3465%2 = OpFunction %void None %7466%29 = OpLabel467%30 = OpImageTexelPointer %_ptr_Image_uint %3 %15 %uint_0468%31 = OpAtomicLoad %uint %30 %int_1 %uint_34816469OpAtomicStore %30 %int_1 %uint_2048 %31470OpReturn471OpFunctionEnd472*/473static const uint32_t words[] = {4740x07230203, 0x00010500, 0x00070000, 0x00000017, 0x00000000, 0x00020011,4750x00000001, 0x00020011, 0x000014e1, 0x00020011, 0x000014e2, 0x0006000b,4760x00000001, 0x4c534c47, 0x6474732e, 0x3035342e, 0x00000000, 0x0003000e,4770x00000000, 0x00000003, 0x0006000f, 0x00000005, 0x00000002, 0x6e69616d,4780x00000000, 0x00000003, 0x00060010, 0x00000002, 0x00000011, 0x00000001,4790x00000001, 0x00000001, 0x00040047, 0x00000003, 0x00000022, 0x00000000,4800x00040047, 0x00000003, 0x00000021, 0x00000001, 0x00020013, 0x00000004,4810x00030021, 0x00000005, 0x00000004, 0x00040015, 0x00000006, 0x00000020,4820x00000000, 0x00090019, 0x00000007, 0x00000006, 0x00000001, 0x00000000,4830x00000000, 0x00000000, 0x00000002, 0x00000021, 0x00040020, 0x00000008,4840x00000000, 0x00000007, 0x0004003b, 0x00000008, 0x00000003, 0x00000000,4850x00040015, 0x00000009, 0x00000020, 0x00000001, 0x00040017, 0x0000000a,4860x00000009, 0x00000002, 0x0004002b, 0x00000009, 0x0000000b, 0x00000000,4870x0005002c, 0x0000000a, 0x0000000c, 0x0000000b, 0x0000000b, 0x0004002b,4880x00000009, 0x0000000d, 0x00000001, 0x0004002b, 0x00000006, 0x0000000e,4890x00000000, 0x00040020, 0x0000000f, 0x0000000b, 0x00000006, 0x0004002b,4900x00000006, 0x00000010, 0x00000001, 0x0004002b, 0x00000006, 0x00000011,4910x00000800, 0x0004002b, 0x00000006, 0x00000012, 0x00008800, 0x00040017,4920x00000013, 0x00000006, 0x00000003, 0x00050036, 0x00000004, 0x00000002,4930x00000000, 0x00000005, 0x000200f8, 0x00000014, 0x0006003c, 0x0000000f,4940x00000015, 0x00000003, 0x0000000c, 0x0000000e, 0x000600e3, 0x00000006,4950x00000016, 0x00000015, 0x0000000d, 0x00000012, 0x000500e4, 0x00000015,4960x0000000d, 0x00000011, 0x00000016, 0x000100fd, 0x00010038,497};498499get_nir(sizeof(words) / sizeof(words[0]), words);500501nir_intrinsic_instr *intrinsic = find_intrinsic(nir_intrinsic_image_deref_load, 0);502ASSERT_NE(intrinsic, nullptr);503EXPECT_NE(nir_intrinsic_access(intrinsic) & ACCESS_VOLATILE, 0);504}505506TEST_F(spirv_test, opatomicstore_image_volatile)507{508/*509OpCapability Shader510OpCapability VulkanMemoryModel511OpCapability VulkanMemoryModelDeviceScope512%1 = OpExtInstImport "GLSL.std.450"513OpMemoryModel Logical Vulkan514OpEntryPoint GLCompute %2 "main" %3515OpExecutionMode %2 LocalSize 1 1 1516OpDecorate %3 DescriptorSet 0517OpDecorate %3 Binding 1518%void = OpTypeVoid519%7 = OpTypeFunction %void520%uint = OpTypeInt 32 0521%10 = OpTypeImage %uint 2D 0 0 0 2 R32ui522%_ptr_UniformConstant_10 = OpTypePointer UniformConstant %10523%3 = OpVariable %_ptr_UniformConstant_10 UniformConstant524%int = OpTypeInt 32 1525%v2int = OpTypeVector %int 2526%int_0 = OpConstant %int 0527%15 = OpConstantComposite %v2int %int_0 %int_0528%int_1 = OpConstant %int 1529%uint_0 = OpConstant %uint 0530%_ptr_Image_uint = OpTypePointer Image %uint531%uint_1 = OpConstant %uint 1532%uint_2048 = OpConstant %uint 2048533%uint_34816 = OpConstant %uint 34816534%v3uint = OpTypeVector %uint 3535%2 = OpFunction %void None %7536%29 = OpLabel537%30 = OpImageTexelPointer %_ptr_Image_uint %3 %15 %uint_0538%31 = OpAtomicLoad %uint %30 %int_1 %uint_2048539OpAtomicStore %30 %int_1 %uint_34816 %31540OpReturn541OpFunctionEnd542*/543static const uint32_t words[] = {5440x07230203, 0x00010500, 0x00070000, 0x00000017, 0x00000000, 0x00020011,5450x00000001, 0x00020011, 0x000014e1, 0x00020011, 0x000014e2, 0x0006000b,5460x00000001, 0x4c534c47, 0x6474732e, 0x3035342e, 0x00000000, 0x0003000e,5470x00000000, 0x00000003, 0x0006000f, 0x00000005, 0x00000002, 0x6e69616d,5480x00000000, 0x00000003, 0x00060010, 0x00000002, 0x00000011, 0x00000001,5490x00000001, 0x00000001, 0x00040047, 0x00000003, 0x00000022, 0x00000000,5500x00040047, 0x00000003, 0x00000021, 0x00000001, 0x00020013, 0x00000004,5510x00030021, 0x00000005, 0x00000004, 0x00040015, 0x00000006, 0x00000020,5520x00000000, 0x00090019, 0x00000007, 0x00000006, 0x00000001, 0x00000000,5530x00000000, 0x00000000, 0x00000002, 0x00000021, 0x00040020, 0x00000008,5540x00000000, 0x00000007, 0x0004003b, 0x00000008, 0x00000003, 0x00000000,5550x00040015, 0x00000009, 0x00000020, 0x00000001, 0x00040017, 0x0000000a,5560x00000009, 0x00000002, 0x0004002b, 0x00000009, 0x0000000b, 0x00000000,5570x0005002c, 0x0000000a, 0x0000000c, 0x0000000b, 0x0000000b, 0x0004002b,5580x00000009, 0x0000000d, 0x00000001, 0x0004002b, 0x00000006, 0x0000000e,5590x00000000, 0x00040020, 0x0000000f, 0x0000000b, 0x00000006, 0x0004002b,5600x00000006, 0x00000010, 0x00000001, 0x0004002b, 0x00000006, 0x00000011,5610x00000800, 0x0004002b, 0x00000006, 0x00000012, 0x00008800, 0x00040017,5620x00000013, 0x00000006, 0x00000003, 0x00050036, 0x00000004, 0x00000002,5630x00000000, 0x00000005, 0x000200f8, 0x00000014, 0x0006003c, 0x0000000f,5640x00000015, 0x00000003, 0x0000000c, 0x0000000e, 0x000600e3, 0x00000006,5650x00000016, 0x00000015, 0x0000000d, 0x00000011, 0x000500e4, 0x00000015,5660x0000000d, 0x00000012, 0x00000016, 0x000100fd, 0x00010038,567};568569get_nir(sizeof(words) / sizeof(words[0]), words);570571nir_intrinsic_instr *intrinsic = find_intrinsic(nir_intrinsic_image_deref_store, 0);572ASSERT_NE(intrinsic, nullptr);573EXPECT_NE(nir_intrinsic_access(intrinsic) & ACCESS_VOLATILE, 0);574}575576577