| #!amber |
| |
| # Copyright 2020 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. |
| |
| # A compute shader test for ModfStruct. |
| |
| # SHADER compute comp_shader GLSL |
| # #version 430 |
| # precision highp float; |
| # |
| # const uint ndp = 1296 / 1; |
| # const uint half_ndp = ndp / 2; |
| # |
| # layout(set = 0, binding = 0) readonly buffer block0 { |
| # uint in_values[half_ndp]; |
| # }; |
| # |
| # layout(set = 0, binding = 1) buffer block1 { |
| # float modf_out[ndp]; |
| # }; |
| # |
| # layout(set = 0, binding = 2) buffer block2 { |
| # float modfStruct_out[ndp]; |
| # }; |
| # |
| # struct modfStructType |
| # { |
| # float x; |
| # float i; |
| # }; |
| # |
| # // Replaced with native function in SPIR-V. |
| # modfStructType modfStruct (float orig) |
| # { |
| # float x, i; |
| # x = modf(orig, i); |
| # modfStructType res = { x, i }; |
| # return res; |
| # } |
| # |
| # void main () |
| # { |
| # for (uint ndx = 0; ndx < ndp; ndx += 2) |
| # { |
| # uint in_uint = in_values[ndx/2]; |
| # float in_float = uintBitsToFloat(in_uint); |
| # modf_out[ndx+1] = modf(in_float, modf_out[ndx]); |
| # modfStructType res = modfStruct(in_float); |
| # modfStruct_out[ndx] = res.i; |
| # modfStruct_out[ndx+1] = res.x; |
| # } |
| # |
| # return; |
| # } |
| # END |
| |
| SHADER compute comp_shader SPIRV-ASM |
| OpCapability Shader |
| %1 = OpExtInstImport "GLSL.std.450" |
| OpMemoryModel Logical GLSL450 |
| OpEntryPoint GLCompute %main "main" |
| OpExecutionMode %main LocalSize 1 1 1 |
| OpDecorate %_arr_uint_uint_648 ArrayStride 4 |
| OpMemberDecorate %block0 0 NonWritable |
| OpMemberDecorate %block0 0 Offset 0 |
| OpDecorate %block0 BufferBlock |
| OpDecorate %_ DescriptorSet 0 |
| OpDecorate %_ Binding 0 |
| OpDecorate %_arr_float_uint_1296 ArrayStride 4 |
| OpMemberDecorate %block1 0 Offset 0 |
| OpDecorate %block1 BufferBlock |
| OpDecorate %__0 DescriptorSet 0 |
| OpDecorate %__0 Binding 1 |
| OpDecorate %_arr_float_uint_1296_0 ArrayStride 4 |
| OpMemberDecorate %block2 0 Offset 0 |
| OpDecorate %block2 BufferBlock |
| OpDecorate %__1 DescriptorSet 0 |
| OpDecorate %__1 Binding 2 |
| %void = OpTypeVoid |
| %3 = OpTypeFunction %void |
| %float = OpTypeFloat 32 |
| %_ptr_Function_float = OpTypePointer Function %float |
| %modfStructType = OpTypeStruct %float %float |
| %9 = OpTypeFunction %modfStructType %_ptr_Function_float |
| %_ptr_Function_modfStructType = OpTypePointer Function %modfStructType |
| %uint = OpTypeInt 32 0 |
| %_ptr_Function_uint = OpTypePointer Function %uint |
| %uint_0 = OpConstant %uint 0 |
| %uint_1296 = OpConstant %uint 1296 |
| %bool = OpTypeBool |
| %uint_648 = OpConstant %uint 648 |
| %_arr_uint_uint_648 = OpTypeArray %uint %uint_648 |
| %block0 = OpTypeStruct %_arr_uint_uint_648 |
| %_ptr_Uniform_block0 = OpTypePointer Uniform %block0 |
| %_ = OpVariable %_ptr_Uniform_block0 Uniform |
| %int = OpTypeInt 32 1 |
| %int_0 = OpConstant %int 0 |
| %uint_2 = OpConstant %uint 2 |
| %_ptr_Uniform_uint = OpTypePointer Uniform %uint |
| %_arr_float_uint_1296 = OpTypeArray %float %uint_1296 |
| %block1 = OpTypeStruct %_arr_float_uint_1296 |
| %_ptr_Uniform_block1 = OpTypePointer Uniform %block1 |
| %__0 = OpVariable %_ptr_Uniform_block1 Uniform |
| %uint_1 = OpConstant %uint 1 |
| %_ptr_Uniform_float = OpTypePointer Uniform %float |
| %_arr_float_uint_1296_0 = OpTypeArray %float %uint_1296 |
| %block2 = OpTypeStruct %_arr_float_uint_1296_0 |
| %_ptr_Uniform_block2 = OpTypePointer Uniform %block2 |
| %__1 = OpVariable %_ptr_Uniform_block2 Uniform |
| %int_1 = OpConstant %int 1 |
| %main = OpFunction %void None %3 |
| %5 = OpLabel |
| %ndx = OpVariable %_ptr_Function_uint Function |
| %in_uint = OpVariable %_ptr_Function_uint Function |
| %in_float = OpVariable %_ptr_Function_float Function |
| %res_0 = OpVariable %_ptr_Function_modfStructType Function |
| OpStore %ndx %uint_0 |
| OpBranch %29 |
| %29 = OpLabel |
| OpLoopMerge %31 %32 None |
| OpBranch %33 |
| %33 = OpLabel |
| %34 = OpLoad %uint %ndx |
| %37 = OpULessThan %bool %34 %uint_1296 |
| OpBranchConditional %37 %30 %31 |
| %30 = OpLabel |
| %46 = OpLoad %uint %ndx |
| %48 = OpUDiv %uint %46 %uint_2 |
| %50 = OpAccessChain %_ptr_Uniform_uint %_ %int_0 %48 |
| %51 = OpLoad %uint %50 |
| OpStore %in_uint %51 |
| %53 = OpLoad %uint %in_uint |
| %54 = OpBitcast %float %53 |
| OpStore %in_float %54 |
| %59 = OpLoad %uint %ndx |
| %61 = OpIAdd %uint %59 %uint_1 |
| %62 = OpLoad %float %in_float |
| %63 = OpLoad %uint %ndx |
| %65 = OpAccessChain %_ptr_Uniform_float %__0 %int_0 %63 |
| %66 = OpExtInst %float %1 Modf %62 %65 |
| %67 = OpAccessChain %_ptr_Uniform_float %__0 %int_0 %61 |
| OpStore %67 %66 |
| %70 = OpLoad %float %in_float |
| %71 = OpExtInst %modfStructType %1 ModfStruct %70 |
| OpStore %res_0 %71 |
| %76 = OpLoad %uint %ndx |
| %78 = OpAccessChain %_ptr_Function_float %res_0 %int_1 |
| %79 = OpLoad %float %78 |
| %80 = OpAccessChain %_ptr_Uniform_float %__1 %int_0 %76 |
| OpStore %80 %79 |
| %81 = OpLoad %uint %ndx |
| %82 = OpIAdd %uint %81 %uint_1 |
| %83 = OpAccessChain %_ptr_Function_float %res_0 %int_0 |
| %84 = OpLoad %float %83 |
| %85 = OpAccessChain %_ptr_Uniform_float %__1 %int_0 %82 |
| OpStore %85 %84 |
| OpBranch %32 |
| %32 = OpLabel |
| %86 = OpLoad %uint %ndx |
| %87 = OpIAdd %uint %86 %uint_2 |
| OpStore %ndx %87 |
| OpBranch %29 |
| %31 = OpLabel |
| OpReturn |
| OpFunctionEnd |
| END |
| |
| BUFFER buf_in DATA_TYPE uint32 SIZE 1296 FILE TEXT input.txt |
| |
| BUFFER buf_modf DATA_TYPE float SIZE 1296 FILL 0.0 |
| BUFFER buf_modfStruct DATA_TYPE float SIZE 1296 FILL 1.0 |
| |
| PIPELINE compute test_pipeline |
| ATTACH comp_shader |
| |
| BIND BUFFER buf_in AS storage DESCRIPTOR_SET 0 BINDING 0 |
| BIND BUFFER buf_modf AS storage DESCRIPTOR_SET 0 BINDING 1 |
| BIND BUFFER buf_modfStruct AS storage DESCRIPTOR_SET 0 BINDING 2 |
| END |
| |
| RUN test_pipeline 1 1 1 |
| |
| EXPECT buf_modf EQ_BUFFER buf_modfStruct |