blob: c868b02b06ff4bf5a5d76a0e541f6428cb2edaec [file] [log] [blame]
#!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 fragment 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 uint ndx_out;
#
# void main ()
# {
# uint xcoord = uint(ndpSqrt * ((position.x + halfGridElementSize + 1) / 2) - 1);
# uint ycoord = uint(ndpSqrt * ((position.y + halfGridElementSize + 1) / 2) - 1);
# ndx_out = xcoord + ycoord * ndpSqrt;
#
# 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 %ndx_out %_
OpDecorate %position Location 0
OpDecorate %ndx_out Flat
OpDecorate %ndx_out Location 0
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
%uint = OpTypeInt 32 0
%float = OpTypeFloat 32
%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_1 = OpConstant %float 1
%uint_1 = OpConstant %uint 1
%_ptr_Output_uint = OpTypePointer Output %uint
%ndx_out = OpVariable %_ptr_Output_uint Output
%uint_36 = OpConstant %uint 36
%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
%_ = OpVariable %_ptr_Output_gl_PerVertex Output
%int = OpTypeInt 32 1
%int_0 = OpConstant %int 0
%float_0 = OpConstant %float 0
%_ptr_Output_v4float = OpTypePointer Output %v4float
%float_1_02777779 = OpConstant %float 1.02777779
%float_18 = OpConstant %float 18
%main = OpFunction %void None %3
%5 = OpLabel
%16 = OpAccessChain %_ptr_Input_float %position %uint_0
%17 = OpLoad %float %16
%21 = OpFAdd %float %17 %float_1_02777779
%24 = OpFMul %float %21 %float_18
%25 = OpFSub %float %24 %float_1
%26 = OpConvertFToU %uint %25
%29 = OpAccessChain %_ptr_Input_float %position %uint_1
%30 = OpLoad %float %29
%32 = OpFAdd %float %30 %float_1_02777779
%34 = OpFMul %float %32 %float_18
%35 = OpFSub %float %34 %float_1
%36 = OpConvertFToU %uint %35
%42 = OpIMul %uint %36 %uint_36
%43 = OpIAdd %uint %26 %42
OpStore %ndx_out %43
%51 = OpLoad %v2float %position
%53 = OpCompositeExtract %float %51 0
%54 = OpCompositeExtract %float %51 1
%55 = OpCompositeConstruct %v4float %53 %54 %float_0 %float_1
%57 = OpAccessChain %_ptr_Output_v4float %_ %int_0
OpStore %57 %55
OpReturn
OpFunctionEnd
END
# SHADER fragment frag_shader GLSL
# #version 430
# precision highp float;
#
# const uint ndp = 1296;
# const vec4 clear_value = vec4(0.0, 0.0, 0.0, 1.0);
#
# layout(set = 0, binding = 0) readonly buffer block0 {
# uint in_values[ndp];
# };
#
# layout (location = 0) flat in uint ndx_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;
#
# 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 in_uint = in_values[ndx_in];
# float in_float = uintBitsToFloat(in_uint);
# float x, i;
# modfStructType res;
#
# x = modf(in_float, i);
# res = modfStruct(in_float);
#
# modf_x_out = clear_value;
# modf_i_out = clear_value;
# modfStruct_x_out = clear_value;
# modfStruct_i_out = clear_value;
# modf_x_out.r = x;
# modf_i_out.r = i;
# modfStruct_x_out.r = res.x;
# modfStruct_i_out.r = res.i;
#
# return;
# }
# END
SHADER fragment frag_shader SPIRV-ASM
OpCapability Shader
%1 = OpExtInstImport "GLSL.std.450"
OpMemoryModel Logical GLSL450
OpEntryPoint Fragment %main "main" %ndx_in %modf_x_out %modf_i_out %modfStruct_x_out %modfStruct_i_out
OpExecutionMode %main OriginUpperLeft
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 %ndx_in Flat
OpDecorate %ndx_in Location 0
OpDecorate %modf_x_out Location 0
OpDecorate %modf_i_out Location 1
OpDecorate %modfStruct_x_out Location 2
OpDecorate %modfStruct_i_out Location 3
%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_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_Input_uint = OpTypePointer Input %uint
%ndx_in = OpVariable %_ptr_Input_uint Input
%_ptr_Uniform_uint = OpTypePointer Uniform %uint
%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
%57 = 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
%uint_0 = OpConstant %uint 0
%_ptr_Output_float = OpTypePointer Output %float
%int_1 = OpConstant %int 1
%main = OpFunction %void None %3
%5 = OpLabel
%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
%37 = OpLoad %uint %ndx_in
%39 = OpAccessChain %_ptr_Uniform_uint %_ %int_0 %37
%40 = OpLoad %uint %39
OpStore %in_uint %40
%42 = OpLoad %uint %in_uint
%43 = OpBitcast %float %42
OpStore %in_float %43
%45 = OpLoad %float %in_float
%47 = OpExtInst %float %1 Modf %45 %i_0
OpStore %x_0 %47
%50 = OpLoad %float %in_float
%51 = OpExtInst %modfStructType %1 ModfStruct %50
OpStore %res_0 %51
OpStore %modf_x_out %57
OpStore %modf_i_out %57
OpStore %modfStruct_x_out %57
OpStore %modfStruct_i_out %57
%61 = OpLoad %float %x_0
%64 = OpAccessChain %_ptr_Output_float %modf_x_out %uint_0
OpStore %64 %61
%65 = OpLoad %float %i_0
%66 = OpAccessChain %_ptr_Output_float %modf_i_out %uint_0
OpStore %66 %65
%67 = OpAccessChain %_ptr_Function_float %res_0 %int_0
%68 = OpLoad %float %67
%69 = OpAccessChain %_ptr_Output_float %modfStruct_x_out %uint_0
OpStore %69 %68
%71 = OpAccessChain %_ptr_Function_float %res_0 %int_1
%72 = OpLoad %float %71
%73 = OpAccessChain %_ptr_Output_float %modfStruct_i_out %uint_0
OpStore %73 %72
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