| #!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 vertex shader test for ModfStruct. |
| |
| # SHADER vertex vert_shader GLSL |
| # #version 430 |
| # precision highp float; |
| # |
| # const uint ndp = 1296; |
| # const uint ndpSqrt = uint(sqrt(ndp)); |
| # const float halfGridElementSize = 1.0 / float(ndpSqrt); |
| # |
| # layout (location = 0) in vec2 position; |
| # layout (location = 0) flat out float modf_x_out; |
| # layout (location = 1) flat out float modf_i_out; |
| # layout (location = 2) flat out float modfStruct_x_out; |
| # layout (location = 3) flat out float modfStruct_i_out; |
| # |
| # layout(set = 0, binding = 0) readonly buffer block0 { |
| # uint in_values[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 () |
| # { |
| # uint xcoord = uint(ndpSqrt * ((position.x + halfGridElementSize + 1) / 2) - 1); |
| # uint ycoord = uint(ndpSqrt * ((position.y + halfGridElementSize + 1) / 2) - 1); |
| # uint ndx = xcoord + ycoord * ndpSqrt; |
| # |
| # uint in_uint = in_values[ndx]; |
| # float in_float = uintBitsToFloat(in_uint); |
| # float x, i; |
| # modfStructType res; |
| # |
| # x = modf(in_float, i); |
| # res = modfStruct(in_float); |
| # |
| # modf_x_out = x; |
| # modf_i_out = i; |
| # modfStruct_x_out = res.x; |
| # modfStruct_i_out = i; |
| # |
| # gl_Position = vec4(position, 0, 1); |
| # |
| # return; |
| # } |
| # END |
| |
| SHADER vertex vert_shader SPIRV-ASM |
| OpCapability Shader |
| %1 = OpExtInstImport "GLSL.std.450" |
| OpMemoryModel Logical GLSL450 |
| OpEntryPoint Vertex %main "main" %position %modf_x_out %modf_i_out %modfStruct_x_out %modfStruct_i_out %__0 |
| OpDecorate %position Location 0 |
| OpDecorate %_arr_uint_uint_1296 ArrayStride 4 |
| OpMemberDecorate %block0 0 NonWritable |
| OpMemberDecorate %block0 0 Offset 0 |
| OpDecorate %block0 BufferBlock |
| OpDecorate %_ DescriptorSet 0 |
| OpDecorate %_ Binding 0 |
| OpDecorate %modf_x_out Flat |
| OpDecorate %modf_x_out Location 0 |
| OpDecorate %modf_i_out Flat |
| OpDecorate %modf_i_out Location 1 |
| OpDecorate %modfStruct_x_out Flat |
| OpDecorate %modfStruct_x_out Location 2 |
| OpDecorate %modfStruct_i_out Flat |
| OpDecorate %modfStruct_i_out Location 3 |
| OpMemberDecorate %gl_PerVertex 0 BuiltIn Position |
| OpMemberDecorate %gl_PerVertex 1 BuiltIn PointSize |
| OpMemberDecorate %gl_PerVertex 2 BuiltIn ClipDistance |
| OpDecorate %gl_PerVertex Block |
| %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 |
| %float_36 = OpConstant %float 36 |
| %v2float = OpTypeVector %float 2 |
| %_ptr_Input_v2float = OpTypePointer Input %v2float |
| %position = OpVariable %_ptr_Input_v2float Input |
| %uint_0 = OpConstant %uint 0 |
| %_ptr_Input_float = OpTypePointer Input %float |
| %float_0_027777778 = OpConstant %float 0.027777778 |
| %float_1 = OpConstant %float 1 |
| %float_2 = OpConstant %float 2 |
| %uint_1 = OpConstant %uint 1 |
| %uint_36 = OpConstant %uint 36 |
| %uint_1296 = OpConstant %uint 1296 |
| %_arr_uint_uint_1296 = OpTypeArray %uint %uint_1296 |
| %block0 = OpTypeStruct %_arr_uint_uint_1296 |
| %_ptr_Uniform_block0 = OpTypePointer Uniform %block0 |
| %_ = OpVariable %_ptr_Uniform_block0 Uniform |
| %int = OpTypeInt 32 1 |
| %int_0 = OpConstant %int 0 |
| %_ptr_Uniform_uint = OpTypePointer Uniform %uint |
| %_ptr_Output_float = OpTypePointer Output %float |
| %modf_x_out = OpVariable %_ptr_Output_float Output |
| %modf_i_out = OpVariable %_ptr_Output_float Output |
| %modfStruct_x_out = OpVariable %_ptr_Output_float Output |
| %modfStruct_i_out = OpVariable %_ptr_Output_float Output |
| %v4float = OpTypeVector %float 4 |
| %_arr_float_uint_1 = OpTypeArray %float %uint_1 |
| %gl_PerVertex = OpTypeStruct %v4float %float %_arr_float_uint_1 |
| %_ptr_Output_gl_PerVertex = OpTypePointer Output %gl_PerVertex |
| %__0 = OpVariable %_ptr_Output_gl_PerVertex Output |
| %float_0 = OpConstant %float 0 |
| %_ptr_Output_v4float = OpTypePointer Output %v4float |
| %main = OpFunction %void None %3 |
| %5 = OpLabel |
| %xcoord = OpVariable %_ptr_Function_uint Function |
| %ycoord = OpVariable %_ptr_Function_uint Function |
| %ndx = OpVariable %_ptr_Function_uint Function |
| %in_uint = OpVariable %_ptr_Function_uint Function |
| %in_float = OpVariable %_ptr_Function_float Function |
| %x_0 = OpVariable %_ptr_Function_float Function |
| %i_0 = OpVariable %_ptr_Function_float Function |
| %res_0 = OpVariable %_ptr_Function_modfStructType Function |
| %34 = OpAccessChain %_ptr_Input_float %position %uint_0 |
| %35 = OpLoad %float %34 |
| %37 = OpFAdd %float %35 %float_0_027777778 |
| %39 = OpFAdd %float %37 %float_1 |
| %41 = OpFDiv %float %39 %float_2 |
| %42 = OpFMul %float %float_36 %41 |
| %43 = OpFSub %float %42 %float_1 |
| %44 = OpConvertFToU %uint %43 |
| OpStore %xcoord %44 |
| %47 = OpAccessChain %_ptr_Input_float %position %uint_1 |
| %48 = OpLoad %float %47 |
| %49 = OpFAdd %float %48 %float_0_027777778 |
| %50 = OpFAdd %float %49 %float_1 |
| %51 = OpFDiv %float %50 %float_2 |
| %52 = OpFMul %float %float_36 %51 |
| %53 = OpFSub %float %52 %float_1 |
| %54 = OpConvertFToU %uint %53 |
| OpStore %ycoord %54 |
| %56 = OpLoad %uint %xcoord |
| %57 = OpLoad %uint %ycoord |
| %59 = OpIMul %uint %57 %uint_36 |
| %60 = OpIAdd %uint %56 %59 |
| OpStore %ndx %60 |
| %69 = OpLoad %uint %ndx |
| %71 = OpAccessChain %_ptr_Uniform_uint %_ %int_0 %69 |
| %72 = OpLoad %uint %71 |
| OpStore %in_uint %72 |
| %74 = OpLoad %uint %in_uint |
| %75 = OpBitcast %float %74 |
| OpStore %in_float %75 |
| %77 = OpLoad %float %in_float |
| %79 = OpExtInst %float %1 Modf %77 %i_0 |
| OpStore %x_0 %79 |
| %82 = OpLoad %float %in_float |
| %83 = OpExtInst %modfStructType %1 ModfStruct %82 |
| OpStore %res_0 %83 |
| %86 = OpLoad %float %x_0 |
| OpStore %modf_x_out %86 |
| %88 = OpLoad %float %i_0 |
| OpStore %modf_i_out %88 |
| %90 = OpAccessChain %_ptr_Function_float %res_0 %int_0 |
| %91 = OpLoad %float %90 |
| OpStore %modfStruct_x_out %91 |
| %93 = OpLoad %float %i_0 |
| OpStore %modfStruct_i_out %93 |
| %99 = OpLoad %v2float %position |
| %101 = OpCompositeExtract %float %99 0 |
| %102 = OpCompositeExtract %float %99 1 |
| %103 = OpCompositeConstruct %v4float %101 %102 %float_0 %float_1 |
| %105 = OpAccessChain %_ptr_Output_v4float %__0 %int_0 |
| OpStore %105 %103 |
| OpReturn |
| OpFunctionEnd |
| END |
| |
| # SHADER fragment frag_shader GLSL |
| # #version 430 |
| # precision highp float; |
| # |
| # layout (location = 0) flat in float modf_x_in; |
| # layout (location = 1) flat in float modf_i_in; |
| # layout (location = 2) flat in float modfStruct_x_in; |
| # layout (location = 3) flat in float modfStruct_i_in; |
| # |
| # layout (location = 0) out vec4 modf_x_out; |
| # layout (location = 1) out vec4 modf_i_out; |
| # layout (location = 2) out vec4 modfStruct_x_out; |
| # layout (location = 3) out vec4 modfStruct_i_out; |
| # |
| # const vec4 clear_value = vec4(0.0, 0.0, 0.0, 1.0); |
| # |
| # void main () |
| # { |
| # modf_x_out = clear_value; |
| # modf_i_out = clear_value; |
| # modfStruct_x_out = clear_value; |
| # modfStruct_i_out = clear_value; |
| # modf_x_out.r = modf_x_in; |
| # modf_i_out.r = modf_i_in; |
| # modfStruct_x_out.r = modfStruct_x_in; |
| # modfStruct_i_out.r = modfStruct_i_in; |
| # } |
| # END |
| |
| SHADER fragment frag_shader SPIRV-ASM |
| OpCapability Shader |
| %1 = OpExtInstImport "GLSL.std.450" |
| OpMemoryModel Logical GLSL450 |
| OpEntryPoint Fragment %main "main" %modf_x_out %modf_i_out %modfStruct_x_out %modfStruct_i_out %modf_x_in %modf_i_in %modfStruct_x_in %modfStruct_i_in |
| OpExecutionMode %main OriginUpperLeft |
| OpDecorate %modf_x_out Location 0 |
| OpDecorate %modf_i_out Location 1 |
| OpDecorate %modfStruct_x_out Location 2 |
| OpDecorate %modfStruct_i_out Location 3 |
| OpDecorate %modf_x_in Flat |
| OpDecorate %modf_x_in Location 0 |
| OpDecorate %modf_i_in Flat |
| OpDecorate %modf_i_in Location 1 |
| OpDecorate %modfStruct_x_in Flat |
| OpDecorate %modfStruct_x_in Location 2 |
| OpDecorate %modfStruct_i_in Flat |
| OpDecorate %modfStruct_i_in Location 3 |
| %void = OpTypeVoid |
| %3 = OpTypeFunction %void |
| %float = OpTypeFloat 32 |
| %v4float = OpTypeVector %float 4 |
| %_ptr_Output_v4float = OpTypePointer Output %v4float |
| %modf_x_out = OpVariable %_ptr_Output_v4float Output |
| %float_0 = OpConstant %float 0 |
| %float_1 = OpConstant %float 1 |
| %12 = OpConstantComposite %v4float %float_0 %float_0 %float_0 %float_1 |
| %modf_i_out = OpVariable %_ptr_Output_v4float Output |
| %modfStruct_x_out = OpVariable %_ptr_Output_v4float Output |
| %modfStruct_i_out = OpVariable %_ptr_Output_v4float Output |
| %_ptr_Input_float = OpTypePointer Input %float |
| %modf_x_in = OpVariable %_ptr_Input_float Input |
| %uint = OpTypeInt 32 0 |
| %uint_0 = OpConstant %uint 0 |
| %_ptr_Output_float = OpTypePointer Output %float |
| %modf_i_in = OpVariable %_ptr_Input_float Input |
| %modfStruct_x_in = OpVariable %_ptr_Input_float Input |
| %modfStruct_i_in = OpVariable %_ptr_Input_float Input |
| %main = OpFunction %void None %3 |
| %5 = OpLabel |
| OpStore %modf_x_out %12 |
| OpStore %modf_i_out %12 |
| OpStore %modfStruct_x_out %12 |
| OpStore %modfStruct_i_out %12 |
| %18 = OpLoad %float %modf_x_in |
| %22 = OpAccessChain %_ptr_Output_float %modf_x_out %uint_0 |
| OpStore %22 %18 |
| %24 = OpLoad %float %modf_i_in |
| %25 = OpAccessChain %_ptr_Output_float %modf_i_out %uint_0 |
| OpStore %25 %24 |
| %27 = OpLoad %float %modfStruct_x_in |
| %28 = OpAccessChain %_ptr_Output_float %modfStruct_x_out %uint_0 |
| OpStore %28 %27 |
| %30 = OpLoad %float %modfStruct_i_in |
| %31 = OpAccessChain %_ptr_Output_float %modfStruct_i_out %uint_0 |
| OpStore %31 %30 |
| OpReturn |
| OpFunctionEnd |
| END |
| |
| BUFFER buf_in DATA_TYPE uint32 SIZE 1296 FILE TEXT input.txt |
| BUFFER vertices DATA_TYPE vec2<float> SIZE 7776 FILE TEXT grid_vertices.txt |
| |
| BUFFER modf_x FORMAT R32G32B32A32_SFLOAT |
| BUFFER modf_i FORMAT R32G32B32A32_SFLOAT |
| BUFFER modfStruct_x FORMAT R32G32B32A32_SFLOAT |
| BUFFER modfStruct_i FORMAT R32G32B32A32_SFLOAT |
| |
| PIPELINE graphics test_pipeline |
| FRAMEBUFFER_SIZE 144 144 |
| |
| ATTACH vert_shader |
| ATTACH frag_shader |
| |
| VERTEX_DATA vertices LOCATION 0 |
| |
| BIND BUFFER buf_in AS storage DESCRIPTOR_SET 0 BINDING 0 |
| BIND BUFFER modf_x AS color LOCATION 0 |
| BIND BUFFER modf_i AS color LOCATION 1 |
| BIND BUFFER modfStruct_x AS color LOCATION 2 |
| BIND BUFFER modfStruct_i AS color LOCATION 3 |
| END |
| |
| RUN test_pipeline DRAW_ARRAY AS TRIANGLE_LIST START_IDX 0 COUNT 7776 |
| |
| EXPECT modf_x EQ_BUFFER modfStruct_x |
| EXPECT modf_i EQ_BUFFER modfStruct_i |