| #!amber |
| |
| DEVICE_FEATURE fragmentStoresAndAtomics |
| DEVICE_FEATURE VariablePointerFeatures.variablePointersStorageBuffer |
| DEVICE_EXTENSION VK_KHR_shader_terminate_invocation |
| |
| SHADER vertex vs SPIRV-ASM |
| ;#version 450 |
| ; |
| ;layout(location = 0) in vec3 position; |
| ;layout(location = 1) in int in_data; |
| ;layout(location = 0) out int out_data; |
| ;void main() { |
| ; gl_Position = vec4(position, 1.0); |
| ; out_data = int(in_data); |
| ;} |
| OpCapability Shader |
| OpMemoryModel Logical GLSL450 |
| OpEntryPoint Vertex %main "main" %position %in_data %out_data %per_vertex |
| OpDecorate %position Location 0 |
| OpDecorate %in_data Location 1 |
| OpDecorate %out_data Location 0 |
| OpDecorate %block Block |
| OpMemberDecorate %block 0 BuiltIn Position |
| %void = OpTypeVoid |
| %bool = OpTypeBool |
| %int = OpTypeInt 32 1 |
| %int_0 = OpConstant %int 0 |
| %float = OpTypeFloat 32 |
| %float_1 = OpConstant %float 1 |
| %float3 = OpTypeVector %float 3 |
| %float4 = OpTypeVector %float 4 |
| %ptr_float3_input = OpTypePointer Input %float3 |
| %ptr_int_input = OpTypePointer Input %int |
| %ptr_int_output = OpTypePointer Output %int |
| %block = OpTypeStruct %float4 |
| %ptr_float4_output = OpTypePointer Output %float4 |
| %ptr_block_output = OpTypePointer Output %block |
| %position = OpVariable %ptr_float3_input Input |
| %in_data = OpVariable %ptr_int_input Input |
| %out_data = OpVariable %ptr_int_output Output |
| %per_vertex = OpVariable %ptr_block_output Output |
| %void_fn = OpTypeFunction %void |
| %main = OpFunction %void None %void_fn |
| %entry = OpLabel |
| %ld_pos = OpLoad %float3 %position |
| %out_pos = OpCompositeConstruct %float4 %ld_pos %float_1 |
| %out_pos_gep = OpAccessChain %ptr_float4_output %per_vertex %int_0 |
| OpStore %out_pos_gep %out_pos |
| OpCopyMemory %out_data %in_data |
| OpReturn |
| OpFunctionEnd |
| END |
| |
| SHADER fragment fs SPIRV-ASM |
| ;#version 450 |
| ; |
| ;#pragma GL_EXT_terminate_invocation : enable |
| ; |
| ;layout(location = 0) in flat int in_data; |
| ;layout(location = 0) out int out_data; |
| ;layout(set = 0, binding = 0) buffer A { uint a[]; } a; |
| ;layout(set = 0, binding = 1) buffer B { uint b[]; } b; |
| ;void main() { |
| ; out_data = 1; |
| ; int x_coord = int(gl_FragCoord.x); |
| ; int y_coord = int(gl_FragCoord.y); |
| ; int combined = (x_coord & 0x1) + (y_coord & 0x1) + in_data; |
| ; int* a_ptr = &a.a[x_coord + 8 * y_coord]; |
| ; if (combined == int(gl_FragCoord.z)) { |
| ; a_ptr = nullptr; |
| ; terminateInvocation; |
| ; } |
| ; |
| ; *a_ptr = b.b[x_coord + 8 * y_coord]; |
| ;} |
| OpCapability Shader |
| OpCapability VariablePointersStorageBuffer |
| OpExtension "SPV_KHR_terminate_invocation" |
| OpExtension "SPV_KHR_storage_buffer_storage_class" |
| OpExtension "SPV_KHR_variable_pointers" |
| OpMemoryModel Logical GLSL450 |
| OpEntryPoint Fragment %main "main" %frag_coord %in_data %out_data |
| OpExecutionMode %main OriginUpperLeft |
| OpDecorate %frag_coord BuiltIn FragCoord |
| OpDecorate %in_data Location 0 |
| OpDecorate %in_data Flat |
| OpDecorate %out_data Location 0 |
| OpDecorate %a DescriptorSet 0 |
| OpDecorate %a Binding 0 |
| OpDecorate %b DescriptorSet 0 |
| OpDecorate %b Binding 1 |
| OpDecorate %a_block Block |
| OpMemberDecorate %a_block 0 Offset 0 |
| OpDecorate %rta ArrayStride 4 |
| %void = OpTypeVoid |
| %bool = OpTypeBool |
| %int = OpTypeInt 32 1 |
| %int_0 = OpConstant %int 0 |
| %int_1 = OpConstant %int 1 |
| %int_8 = OpConstant %int 8 |
| %float = OpTypeFloat 32 |
| %float4 = OpTypeVector %float 4 |
| %ptr_int_input = OpTypePointer Input %int |
| %ptr_int_output = OpTypePointer Output %int |
| %ptr_float4_input = OpTypePointer Input %float4 |
| %frag_coord = OpVariable %ptr_float4_input Input |
| %in_data = OpVariable %ptr_int_input Input |
| %out_data = OpVariable %ptr_int_output Output |
| %rta = OpTypeRuntimeArray %int |
| %a_block = OpTypeStruct %rta |
| %ptr_int_ssbo = OpTypePointer StorageBuffer %int |
| %ptr_a_ssbo = OpTypePointer StorageBuffer %a_block |
| %a = OpVariable %ptr_a_ssbo StorageBuffer |
| %b = OpVariable %ptr_a_ssbo StorageBuffer |
| %nullptr = OpConstantNull %ptr_int_ssbo |
| %void_fn = OpTypeFunction %void |
| %main = OpFunction %void None %void_fn |
| %entry = OpLabel |
| OpStore %out_data %int_1 |
| %coord = OpLoad %float4 %frag_coord |
| %x_coord = OpCompositeExtract %float %coord 0 |
| %y_coord = OpCompositeExtract %float %coord 1 |
| %z_coord = OpCompositeExtract %float %coord 2 |
| %x = OpConvertFToS %int %x_coord |
| %y = OpConvertFToS %int %y_coord |
| %z = OpConvertFToS %int %z_coord |
| %x_and_1 = OpBitwiseAnd %int %x %int_1 |
| %y_and_1 = OpBitwiseAnd %int %y %int_1 |
| %add = OpIAdd %int %x_and_1 %y_and_1 |
| %ld_in_data = OpLoad %int %in_data |
| %combined = OpIAdd %int %add %ld_in_data |
| %cmp = OpIEqual %bool %combined %z |
| %offset = OpIMul %int %y %int_8 |
| %idx = OpIAdd %int %x %offset |
| %b_ptr = OpAccessChain %ptr_int_ssbo %b %int_0 %idx |
| OpSelectionMerge %exit None |
| OpBranchConditional %cmp %then %exit |
| %then = OpLabel |
| OpTerminateInvocation |
| %exit = OpLabel |
| %a_gep = OpAccessChain %ptr_int_ssbo %a %int_0 %idx |
| %a_sel = OpSelect %ptr_int_ssbo %cmp %nullptr %a_gep |
| OpCopyMemory %a_sel %b_ptr |
| OpReturn |
| OpFunctionEnd |
| END |
| |
| BUFFER position_buf DATA_TYPE vec3<float> DATA |
| -1 -1 0 |
| -1 1 0 |
| 1 -1 0 |
| |
| -1 1 0 |
| 1 -1 0 |
| 1 1 0 |
| END |
| |
| BUFFER in_data_buf DATA_TYPE int32 SIZE 6 FILL 0 |
| |
| IMAGE out_data DATA_TYPE int32 DIM_2D WIDTH 8 HEIGHT 8 FILL 0 |
| BUFFER a_buf DATA_TYPE int32 SIZE 64 FILL 0 |
| BUFFER b_buf DATA_TYPE int32 SIZE 64 SERIES_FROM 0 INC_BY 1 |
| BUFFER expect_buf DATA_TYPE int32 DATA |
| 0 1 0 3 0 5 0 7 |
| 8 9 10 11 12 13 14 15 |
| 0 17 0 19 0 21 0 23 |
| 24 25 26 27 28 29 30 31 |
| 0 33 0 35 0 37 0 39 |
| 40 41 42 43 44 45 46 47 |
| 0 49 0 51 0 53 0 55 |
| 56 57 58 59 60 61 62 63 |
| END |
| |
| PIPELINE graphics gpipe |
| ATTACH vs |
| ATTACH fs |
| |
| FRAMEBUFFER_SIZE 8 8 |
| VERTEX_DATA position_buf LOCATION 0 |
| VERTEX_DATA in_data_buf LOCATION 1 |
| BIND BUFFER out_data AS color LOCATION 0 |
| BIND BUFFER a_buf AS storage DESCRIPTOR_SET 0 BINDING 0 |
| BIND BUFFER b_buf AS storage DESCRIPTOR_SET 0 BINDING 1 |
| END |
| |
| RUN gpipe DRAW_ARRAY AS TRIANGLE_LIST START_IDX 0 COUNT 6 |
| EXPECT a_buf EQ_BUFFER expect_buf |
| |