| #!amber |
| |
| # Copyright 2021 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 FrexpStruct. |
| |
| # 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 vec2 frexp_x_out; |
| # layout (location = 1) flat out vec2 frexp_exp_out; |
| # layout (location = 2) flat out vec2 frexpStruct_x_out; |
| # layout (location = 3) flat out vec2 frexpStruct_exp_out; |
| # |
| # layout(set = 0, binding = 0) readonly buffer block0 { |
| # uvec2 in_values[ndp]; |
| # }; |
| # |
| # struct frexpStructType |
| # { |
| # vec2 x; |
| # ivec2 exp; |
| # }; |
| # |
| # // Replaced with native function in SPIR-V. |
| # frexpStructType frexpStruct (vec2 orig) |
| # { |
| # vec2 x; |
| # ivec2 exp; |
| # x = frexp(orig, exp); |
| # frexpStructType res = { x, exp }; |
| # 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; |
| # |
| # uvec2 in_uint = in_values[ndx]; |
| # vec2 in_float = uintBitsToFloat(in_uint); |
| # vec2 x; |
| # ivec2 exp; |
| # frexpStructType res; |
| # |
| # x = frexp(in_float, exp); |
| # res = frexpStruct(in_float); |
| # |
| # frexp_x_out = x; |
| # frexp_exp_out = intBitsToFloat(exp); |
| # frexpStruct_x_out = res.x; |
| # frexpStruct_exp_out = intBitsToFloat(res.exp); |
| # |
| # 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 %frexp_x_out %frexp_exp_out %frexpStruct_x_out %frexpStruct_exp_out %__0 |
| OpDecorate %position Location 0 |
| OpDecorate %_arr_v2uint_uint_1296 ArrayStride 8 |
| OpMemberDecorate %block0 0 NonWritable |
| OpMemberDecorate %block0 0 Offset 0 |
| OpDecorate %block0 BufferBlock |
| OpDecorate %_ DescriptorSet 0 |
| OpDecorate %_ Binding 0 |
| OpDecorate %frexp_x_out Flat |
| OpDecorate %frexp_x_out Location 0 |
| OpDecorate %frexp_exp_out Flat |
| OpDecorate %frexp_exp_out Location 1 |
| OpDecorate %frexpStruct_x_out Flat |
| OpDecorate %frexpStruct_x_out Location 2 |
| OpDecorate %frexpStruct_exp_out Flat |
| OpDecorate %frexpStruct_exp_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 |
| %v2float = OpTypeVector %float 2 |
| %_ptr_Function_v2float = OpTypePointer Function %v2float |
| %int = OpTypeInt 32 1 |
| %v2int = OpTypeVector %int 2 |
| %frexpStructType = OpTypeStruct %v2float %v2int |
| %12 = OpTypeFunction %frexpStructType %_ptr_Function_v2float |
| %_ptr_Function_v2int = OpTypePointer Function %v2int |
| %_ptr_Function_frexpStructType = OpTypePointer Function %frexpStructType |
| %uint = OpTypeInt 32 0 |
| %_ptr_Function_uint = OpTypePointer Function %uint |
| %float_36 = OpConstant %float 36 |
| %_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 |
| %v2uint = OpTypeVector %uint 2 |
| %_ptr_Function_v2uint = OpTypePointer Function %v2uint |
| %uint_1296 = OpConstant %uint 1296 |
| %_arr_v2uint_uint_1296 = OpTypeArray %v2uint %uint_1296 |
| %block0 = OpTypeStruct %_arr_v2uint_uint_1296 |
| %_ptr_Uniform_block0 = OpTypePointer Uniform %block0 |
| %_ = OpVariable %_ptr_Uniform_block0 Uniform |
| %int_0 = OpConstant %int 0 |
| %_ptr_Uniform_v2uint = OpTypePointer Uniform %v2uint |
| %_ptr_Output_v2float = OpTypePointer Output %v2float |
| %frexp_x_out = OpVariable %_ptr_Output_v2float Output |
| %frexp_exp_out = OpVariable %_ptr_Output_v2float Output |
| %frexpStruct_x_out = OpVariable %_ptr_Output_v2float Output |
| %frexpStruct_exp_out = OpVariable %_ptr_Output_v2float Output |
| %int_1 = OpConstant %int 1 |
| %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_v2uint Function |
| %in_float = OpVariable %_ptr_Function_v2float Function |
| %x_0 = OpVariable %_ptr_Function_v2float Function |
| %exp_0 = OpVariable %_ptr_Function_v2int Function |
| %res_0 = OpVariable %_ptr_Function_frexpStructType Function |
| %37 = OpAccessChain %_ptr_Input_float %position %uint_0 |
| %38 = OpLoad %float %37 |
| %40 = OpFAdd %float %38 %float_0_027777778 |
| %42 = OpFAdd %float %40 %float_1 |
| %44 = OpFDiv %float %42 %float_2 |
| %45 = OpFMul %float %float_36 %44 |
| %46 = OpFSub %float %45 %float_1 |
| %47 = OpConvertFToU %uint %46 |
| OpStore %xcoord %47 |
| %50 = OpAccessChain %_ptr_Input_float %position %uint_1 |
| %51 = OpLoad %float %50 |
| %52 = OpFAdd %float %51 %float_0_027777778 |
| %53 = OpFAdd %float %52 %float_1 |
| %54 = OpFDiv %float %53 %float_2 |
| %55 = OpFMul %float %float_36 %54 |
| %56 = OpFSub %float %55 %float_1 |
| %57 = OpConvertFToU %uint %56 |
| OpStore %ycoord %57 |
| %59 = OpLoad %uint %xcoord |
| %60 = OpLoad %uint %ycoord |
| %62 = OpIMul %uint %60 %uint_36 |
| %63 = OpIAdd %uint %59 %62 |
| OpStore %ndx %63 |
| %73 = OpLoad %uint %ndx |
| %75 = OpAccessChain %_ptr_Uniform_v2uint %_ %int_0 %73 |
| %76 = OpLoad %v2uint %75 |
| OpStore %in_uint %76 |
| %78 = OpLoad %v2uint %in_uint |
| %79 = OpBitcast %v2float %78 |
| OpStore %in_float %79 |
| %81 = OpLoad %v2float %in_float |
| %83 = OpExtInst %v2float %1 Frexp %81 %exp_0 |
| OpStore %x_0 %83 |
| %86 = OpLoad %v2float %in_float |
| %87 = OpExtInst %frexpStructType %1 FrexpStruct %86 |
| OpStore %res_0 %87 |
| %90 = OpLoad %v2float %x_0 |
| OpStore %frexp_x_out %90 |
| %92 = OpLoad %v2int %exp_0 |
| %93 = OpBitcast %v2float %92 |
| OpStore %frexp_exp_out %93 |
| %95 = OpAccessChain %_ptr_Function_v2float %res_0 %int_0 |
| %96 = OpLoad %v2float %95 |
| OpStore %frexpStruct_x_out %96 |
| %99 = OpAccessChain %_ptr_Function_v2int %res_0 %int_1 |
| %100 = OpLoad %v2int %99 |
| %101 = OpBitcast %v2float %100 |
| OpStore %frexpStruct_exp_out %101 |
| %107 = OpLoad %v2float %position |
| %109 = OpCompositeExtract %float %107 0 |
| %110 = OpCompositeExtract %float %107 1 |
| %111 = OpCompositeConstruct %v4float %109 %110 %float_0 %float_1 |
| %113 = OpAccessChain %_ptr_Output_v4float %__0 %int_0 |
| OpStore %113 %111 |
| OpReturn |
| OpFunctionEnd |
| END |
| |
| # SHADER fragment frag_shader GLSL |
| # #version 430 |
| # precision highp float; |
| # |
| # layout (location = 0) flat in vec2 frexp_x_in; |
| # layout (location = 1) flat in vec2 frexp_exp_in; |
| # layout (location = 2) flat in vec2 frexpStruct_x_in; |
| # layout (location = 3) flat in vec2 frexpStruct_exp_in; |
| # |
| # layout (location = 0) out vec4 frexp_x_out; |
| # layout (location = 1) out vec4 frexp_exp_out; |
| # layout (location = 2) out vec4 frexpStruct_x_out; |
| # layout (location = 3) out vec4 frexpStruct_exp_out; |
| # |
| # const vec4 clear_value = vec4(0.0, 0.0, 0.0, 1.0); |
| # |
| # void main () |
| # { |
| # frexp_x_out = clear_value; |
| # frexp_exp_out = clear_value; |
| # frexpStruct_x_out = clear_value; |
| # frexpStruct_exp_out = clear_value; |
| # frexp_x_out.rg = frexp_x_in; |
| # frexp_exp_out.rg = frexp_exp_in; |
| # frexpStruct_x_out.rg = frexpStruct_x_in; |
| # frexpStruct_exp_out.rg = frexpStruct_exp_in; |
| # } |
| # END |
| |
| SHADER fragment frag_shader SPIRV-ASM |
| OpCapability Shader |
| %1 = OpExtInstImport "GLSL.std.450" |
| OpMemoryModel Logical GLSL450 |
| OpEntryPoint Fragment %main "main" %frexp_x_out %frexp_exp_out %frexpStruct_x_out %frexpStruct_exp_out %frexp_x_in %frexp_exp_in %frexpStruct_x_in %frexpStruct_exp_in |
| OpExecutionMode %main OriginUpperLeft |
| OpDecorate %frexp_x_out Location 0 |
| OpDecorate %frexp_exp_out Location 1 |
| OpDecorate %frexpStruct_x_out Location 2 |
| OpDecorate %frexpStruct_exp_out Location 3 |
| OpDecorate %frexp_x_in Flat |
| OpDecorate %frexp_x_in Location 0 |
| OpDecorate %frexp_exp_in Flat |
| OpDecorate %frexp_exp_in Location 1 |
| OpDecorate %frexpStruct_x_in Flat |
| OpDecorate %frexpStruct_x_in Location 2 |
| OpDecorate %frexpStruct_exp_in Flat |
| OpDecorate %frexpStruct_exp_in Location 3 |
| %void = OpTypeVoid |
| %3 = OpTypeFunction %void |
| %float = OpTypeFloat 32 |
| %v4float = OpTypeVector %float 4 |
| %_ptr_Output_v4float = OpTypePointer Output %v4float |
| %frexp_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 |
| %frexp_exp_out = OpVariable %_ptr_Output_v4float Output |
| %frexpStruct_x_out = OpVariable %_ptr_Output_v4float Output |
| %frexpStruct_exp_out = OpVariable %_ptr_Output_v4float Output |
| %v2float = OpTypeVector %float 2 |
| %_ptr_Input_v2float = OpTypePointer Input %v2float |
| %frexp_x_in = OpVariable %_ptr_Input_v2float Input |
| %frexp_exp_in = OpVariable %_ptr_Input_v2float Input |
| %frexpStruct_x_in = OpVariable %_ptr_Input_v2float Input |
| %frexpStruct_exp_in = OpVariable %_ptr_Input_v2float Input |
| %main = OpFunction %void None %3 |
| %5 = OpLabel |
| OpStore %frexp_x_out %12 |
| OpStore %frexp_exp_out %12 |
| OpStore %frexpStruct_x_out %12 |
| OpStore %frexpStruct_exp_out %12 |
| %19 = OpLoad %v2float %frexp_x_in |
| %20 = OpLoad %v4float %frexp_x_out |
| %21 = OpVectorShuffle %v4float %20 %19 4 5 2 3 |
| OpStore %frexp_x_out %21 |
| %23 = OpLoad %v2float %frexp_exp_in |
| %24 = OpLoad %v4float %frexp_exp_out |
| %25 = OpVectorShuffle %v4float %24 %23 4 5 2 3 |
| OpStore %frexp_exp_out %25 |
| %27 = OpLoad %v2float %frexpStruct_x_in |
| %28 = OpLoad %v4float %frexpStruct_x_out |
| %29 = OpVectorShuffle %v4float %28 %27 4 5 2 3 |
| OpStore %frexpStruct_x_out %29 |
| %31 = OpLoad %v2float %frexpStruct_exp_in |
| %32 = OpLoad %v4float %frexpStruct_exp_out |
| %33 = OpVectorShuffle %v4float %32 %31 4 5 2 3 |
| OpStore %frexpStruct_exp_out %33 |
| 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 frexp_x FORMAT R32G32B32A32_SFLOAT |
| BUFFER frexp_exp FORMAT R32G32B32A32_SFLOAT |
| BUFFER frexpStruct_x FORMAT R32G32B32A32_SFLOAT |
| BUFFER frexpStruct_exp 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 frexp_x AS color LOCATION 0 |
| BIND BUFFER frexp_exp AS color LOCATION 1 |
| BIND BUFFER frexpStruct_x AS color LOCATION 2 |
| BIND BUFFER frexpStruct_exp AS color LOCATION 3 |
| END |
| |
| RUN test_pipeline DRAW_ARRAY AS TRIANGLE_LIST START_IDX 0 COUNT 7776 |
| |
| EXPECT frexp_x EQ_BUFFER frexpStruct_x |
| EXPECT frexp_exp EQ_BUFFER frexpStruct_exp |