From 55b629f655015025eca62a0b764f1c02b219eeff Mon Sep 17 00:00:00 2001 From: Jaebaek Seo Date: Mon, 10 Dec 2018 13:16:59 -0500 Subject: Vulkan: enable extension support (#154) This commit checks if extensions given in `[require]` section are supported by physical device and enables them when creating the logical device. Fixes #97 --- .../compute_in_spirv_generated_by_clspv.amber | 163 +++++++++++++++++++++ 1 file changed, 163 insertions(+) create mode 100644 tests/cases/compute_in_spirv_generated_by_clspv.amber (limited to 'tests') diff --git a/tests/cases/compute_in_spirv_generated_by_clspv.amber b/tests/cases/compute_in_spirv_generated_by_clspv.amber new file mode 100644 index 0000000..fba1eaf --- /dev/null +++ b/tests/cases/compute_in_spirv_generated_by_clspv.amber @@ -0,0 +1,163 @@ +[comment] +Source code in OpenCL C: + +typedef struct { int arr[2]; } S1; +typedef struct { S1 s1; int a; S1 s2; } S2; + +S2 make_s2(int n) { + S2 s2; + s2.s1.arr[0] = n; + s2.s1.arr[1] = n; + s2.a = n; + s2.s2.arr[0] = n; + s2.s2.arr[1] = n; + return s2; +} + +S2 choose(int n) { + if (n > 0) return make_s2(n - 5); + return make_s2(0); +} + +kernel void foo(global S2 *data, int n) { + *data = choose(n); +} + +The following SPIR-V code was generated by CLSPV with -cl-opt-disable option. +GIT_COMMIT = 8638849b2167fcba90dbff0ee4cfe7dbf0380d24 + +[compute shader spirv] +; SPIR-V +; Version: 1.0 +; Generator: Codeplay; 0 +; Bound: 71 +; Schema: 0 + OpCapability Shader + OpCapability VariablePointers + OpExtension "SPV_KHR_storage_buffer_storage_class" + OpExtension "SPV_KHR_variable_pointers" + OpMemoryModel Logical GLSL450 + OpEntryPoint GLCompute %52 "main" + OpSource OpenCL_C 120 + OpDecorate %24 SpecId 0 + OpDecorate %25 SpecId 1 + OpDecorate %26 SpecId 2 + OpMemberDecorate %_struct_4 0 Offset 0 + OpMemberDecorate %_struct_5 0 Offset 0 + OpMemberDecorate %_struct_5 1 Offset 8 + OpMemberDecorate %_struct_5 2 Offset 12 + OpDecorate %_runtimearr__struct_5 ArrayStride 20 + OpMemberDecorate %_struct_7 0 Offset 0 + OpDecorate %_struct_7 Block + OpMemberDecorate %_struct_9 0 Offset 0 + OpDecorate %_struct_9 Block + OpDecorate %gl_WorkGroupSize BuiltIn WorkgroupSize + OpDecorate %29 DescriptorSet 0 + OpDecorate %29 Binding 0 + OpDecorate %30 DescriptorSet 0 + OpDecorate %30 Binding 1 + OpDecorate %_arr_uint_uint_2 ArrayStride 4 + %uint = OpTypeInt 32 0 + %uint_2 = OpConstant %uint 2 +%_arr_uint_uint_2 = OpTypeArray %uint %uint_2 + %_struct_4 = OpTypeStruct %_arr_uint_uint_2 + %_struct_5 = OpTypeStruct %_struct_4 %uint %_struct_4 +%_runtimearr__struct_5 = OpTypeRuntimeArray %_struct_5 + %_struct_7 = OpTypeStruct %_runtimearr__struct_5 +%_ptr_StorageBuffer__struct_7 = OpTypePointer StorageBuffer %_struct_7 + %_struct_9 = OpTypeStruct %uint +%_ptr_StorageBuffer__struct_9 = OpTypePointer StorageBuffer %_struct_9 + %void = OpTypeVoid + %12 = OpTypeFunction %void +%_ptr_StorageBuffer_uint = OpTypePointer StorageBuffer %uint + %14 = OpTypeFunction %_struct_5 %uint + %bool = OpTypeBool + %v3uint = OpTypeVector %uint 3 +%_ptr_Private_v3uint = OpTypePointer Private %v3uint + %uint_0 = OpConstant %uint 0 + %uint_1 = OpConstant %uint 1 + %20 = OpUndef %_struct_5 + %false = OpConstantFalse %bool + %true = OpConstantTrue %bool +%uint_4294967291 = OpConstant %uint 4294967291 + %24 = OpSpecConstant %uint 1 + %25 = OpSpecConstant %uint 1 + %26 = OpSpecConstant %uint 1 +%gl_WorkGroupSize = OpSpecConstantComposite %v3uint %24 %25 %26 + %28 = OpVariable %_ptr_Private_v3uint Private %gl_WorkGroupSize + %29 = OpVariable %_ptr_StorageBuffer__struct_7 StorageBuffer + %30 = OpVariable %_ptr_StorageBuffer__struct_9 StorageBuffer + %31 = OpFunction %_struct_5 Const %14 + %32 = OpFunctionParameter %uint + %33 = OpLabel + %34 = OpCompositeConstruct %_arr_uint_uint_2 %32 %32 + %35 = OpCompositeConstruct %_struct_4 %34 + %36 = OpCompositeConstruct %_struct_5 %35 %32 %35 + OpReturnValue %36 + OpFunctionEnd + %37 = OpFunction %_struct_5 Const %14 + %38 = OpFunctionParameter %uint + %39 = OpLabel + %40 = OpSGreaterThan %bool %38 %uint_0 + %41 = OpLogicalNot %bool %40 + OpSelectionMerge %44 None + OpBranchConditional %41 %42 %44 + %42 = OpLabel + %43 = OpFunctionCall %_struct_5 %31 %uint_0 + OpBranch %44 + %44 = OpLabel + %46 = OpPhi %bool %false %42 %true %39 + %45 = OpPhi %_struct_5 %43 %42 %20 %39 + OpSelectionMerge %47 None + OpBranchConditional %46 %49 %47 + %47 = OpLabel + %48 = OpPhi %_struct_5 %45 %44 %51 %49 + OpReturnValue %48 + %49 = OpLabel + %50 = OpIAdd %uint %38 %uint_4294967291 + %51 = OpFunctionCall %_struct_5 %31 %50 + OpBranch %47 + OpFunctionEnd + %52 = OpFunction %void None %12 + %53 = OpLabel + %54 = OpAccessChain %_ptr_StorageBuffer_uint %30 %uint_0 + %55 = OpLoad %uint %54 + %56 = OpFunctionCall %_struct_5 %37 %55 + %57 = OpCompositeExtract %_struct_4 %56 0 + %58 = OpCompositeExtract %_arr_uint_uint_2 %57 0 + %59 = OpCompositeExtract %uint %58 0 + %60 = OpCompositeExtract %uint %58 1 + %61 = OpCompositeExtract %uint %56 1 + %62 = OpCompositeExtract %_struct_4 %56 2 + %63 = OpCompositeExtract %_arr_uint_uint_2 %62 0 + %64 = OpCompositeExtract %uint %63 0 + %65 = OpCompositeExtract %uint %63 1 + %66 = OpAccessChain %_ptr_StorageBuffer_uint %29 %uint_0 %uint_0 %uint_0 %uint_0 %uint_0 + OpStore %66 %59 + %67 = OpAccessChain %_ptr_StorageBuffer_uint %29 %uint_0 %uint_0 %uint_0 %uint_0 %uint_1 + OpStore %67 %60 + %68 = OpAccessChain %_ptr_StorageBuffer_uint %29 %uint_0 %uint_0 %uint_1 + OpStore %68 %61 + %69 = OpAccessChain %_ptr_StorageBuffer_uint %29 %uint_0 %uint_0 %uint_2 %uint_0 %uint_0 + OpStore %69 %64 + %70 = OpAccessChain %_ptr_StorageBuffer_uint %29 %uint_0 %uint_0 %uint_2 %uint_0 %uint_1 + OpStore %70 %65 + OpReturn + OpFunctionEnd +[require] +VK_KHR_storage_buffer_storage_class +VK_KHR_variable_pointers + +[test] +# ssbo [bind] subdata [type] [offset] [values ...] +ssbo 0 subdata int 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 +ssbo 1 subdata int 0 13 + +compute 3 1 1 + +# probe ssbo [type] [bind] [offset] == [values ...] +probe ssbo int 0 0 == 8 +probe ssbo int 0 4 == 8 +probe ssbo int 0 8 == 8 +probe ssbo int 0 12 == 8 +probe ssbo int 0 16 == 8 -- cgit v1.2.3