Test SampledImage as function argument
authorRicardo Garcia <rgarcia@igalia.com>
Thu, 13 Feb 2020 12:17:40 +0000 (13:17 +0100)
committerAlexander Galazin <Alexander.Galazin@arm.com>
Thu, 5 Mar 2020 09:35:26 +0000 (04:35 -0500)
Add test to check sampled images work properly when used as function
arguments.

New test:
dEQP-VK.spirv_assembly.instruction.function_params.sampler_param

Components: Vulkan
VK-GL-CTS issue: 2218

Change-Id: I4b760cf0e5cf8ad980fd33e9b237778a2451a243

android/cts/master/vk-master.txt
external/vulkancts/data/vulkan/amber/spirv_assembly/instruction/function_params/sampler_param.amber [new file with mode: 0644]
external/vulkancts/modules/vulkan/spirv_assembly/vktSpvAsmInstructionTests.cpp
external/vulkancts/mustpass/master/vk-default-no-waivers.txt
external/vulkancts/mustpass/master/vk-default.txt

index 51a3b2b..3da62c0 100644 (file)
@@ -325083,6 +325083,7 @@ dEQP-VK.spirv_assembly.instruction.spirv1p4.uconvert.spec_const_opt_truncate_983
 dEQP-VK.spirv_assembly.instruction.spirv1p4.uconvert.spec_const_opt_zero_extend_n4096
 dEQP-VK.spirv_assembly.instruction.spirv1p4.wrap.no_signed_wrap
 dEQP-VK.spirv_assembly.instruction.spirv1p4.wrap.no_unsigned_wrap
+dEQP-VK.spirv_assembly.instruction.function_params.sampler_param
 dEQP-VK.spirv_assembly.type.scalar.i8.negate_vert
 dEQP-VK.spirv_assembly.type.scalar.i8.negate_tessc
 dEQP-VK.spirv_assembly.type.scalar.i8.negate_tesse
diff --git a/external/vulkancts/data/vulkan/amber/spirv_assembly/instruction/function_params/sampler_param.amber b/external/vulkancts/data/vulkan/amber/spirv_assembly/instruction/function_params/sampler_param.amber
new file mode 100644 (file)
index 0000000..2585c31
--- /dev/null
@@ -0,0 +1,130 @@
+#!amber
+
+# Copyright 2020 Valve Corporation.
+# Copyright 2020 The Khronos Group Inc.
+#
+# 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.
+
+SHADER vertex vtx_passthrough PASSTHROUGH
+
+SHADER fragment frag_green GLSL
+#version 450
+layout(location=0) out vec4 out_color;
+void main() {
+  out_color = vec4(0.0, 1.0, 0.0, 1.0);
+}
+END
+
+SHADER vertex vtx_shader GLSL
+#version 450
+
+layout(location = 0) in vec4 position;
+layout(location = 0) out vec2 textureCoordinates;
+
+void main() {
+  gl_Position = position;
+  textureCoordinates = vec2(0.0, 0.0);
+}
+END
+
+SHADER fragment frag_shader SPIRV-ASM
+                           OpCapability Shader
+                           OpMemoryModel Logical GLSL450
+                           OpEntryPoint Fragment %main "main" %fragColor %vtxTexCoords
+                           OpExecutionMode %main OriginUpperLeft
+                           OpDecorate %fragColor Location 0 ; Output
+                           OpDecorate %vtxTexCoords Location 0 ; Input
+                           OpDecorate %sampler_ptr DescriptorSet 0
+                           OpDecorate %sampler_ptr Binding 0
+
+                           ; Basic types.
+                   %void = OpTypeVoid
+            %void_func_t = OpTypeFunction %void
+                  %float = OpTypeFloat 32
+                %v2float = OpTypeVector %float 2
+                %v4float = OpTypeVector %float 4
+               %image_2d = OpTypeImage %float 2D 0 0 0 1 Unknown
+            %sampled_img = OpTypeSampledImage %image_2d
+        %sampling_func_t = OpTypeFunction %v4float %sampled_img %v2float
+
+                           ; Pointer types.
+%sampled_img_uniform_ptr = OpTypePointer UniformConstant %sampled_img
+        %v4float_out_ptr = OpTypePointer Output %v4float
+      %v2float_input_ptr = OpTypePointer Input %v2float
+
+                           ; In/Out variables.
+              %fragColor = OpVariable %v4float_out_ptr Output
+            %sampler_ptr = OpVariable %sampled_img_uniform_ptr UniformConstant
+           %vtxTexCoords = OpVariable %v2float_input_ptr Input
+
+                           ; Main function.
+                   %main = OpFunction %void None %void_func_t
+             %main_label = OpLabel
+             %tex_coords = OpLoad %v2float %vtxTexCoords
+            %sampler_arg = OpLoad %sampled_img %sampler_ptr
+         %frag_color_val = OpFunctionCall %v4float %sampling_func %sampler_arg %tex_coords
+                           OpStore %fragColor %frag_color_val
+                           OpReturn
+                           OpFunctionEnd
+
+                           ; Auxiliar texture sampling function, receiving a sampled image as its argument.
+          %sampling_func = OpFunction %v4float None %sampling_func_t
+                %sampler = OpFunctionParameter %sampled_img
+                 %coords = OpFunctionParameter %v2float
+    %sampling_func_label = OpLabel
+                 %retval = OpImageSampleImplicitLod %v4float %sampler %coords
+                           OpReturnValue %retval
+                           OpFunctionEnd
+END
+
+# Full-screen quad.
+BUFFER position_buf DATA_TYPE vec4<float> DATA
+-1 -1    0 1
+ 1 -1    0 1
+-1  1    0 1
+-1  1    0 1
+ 1 -1    0 1
+ 1  1    0 1
+END
+
+BUFFER framebuffer FORMAT B8G8R8A8_UNORM
+BUFFER texture FORMAT R8G8B8A8_UNORM
+SAMPLER sampler
+
+PIPELINE graphics texgen_pipeline
+  ATTACH vtx_passthrough
+  ATTACH frag_green
+
+  FRAMEBUFFER_SIZE 1 1
+  BIND BUFFER texture AS color LOCATION 0
+END
+
+PIPELINE graphics main_pipeline
+  ATTACH vtx_shader
+  ATTACH frag_shader
+
+  VERTEX_DATA position_buf LOCATION 0
+  BIND BUFFER texture AS combined_image_sampler SAMPLER sampler DESCRIPTOR_SET 0 BINDING 0
+
+  FRAMEBUFFER_SIZE 64 64
+  BIND BUFFER framebuffer AS color LOCATION 0
+END
+
+CLEAR texgen_pipeline
+RUN texgen_pipeline DRAW_RECT POS 0 0 SIZE 1 1
+EXPECT texture IDX 0 0 SIZE 1 1 EQ_RGBA 0 255 0 255
+
+CLEAR_COLOR main_pipeline 0 0 0 255
+CLEAR main_pipeline
+RUN main_pipeline DRAW_ARRAY AS TRIANGLE_LIST START_IDX 0 COUNT 6
+EXPECT framebuffer IDX 0 0 SIZE 64 64 EQ_RGBA 0 255 0 255
index 07a8339..a947fdc 100644 (file)
@@ -20123,6 +20123,34 @@ tcu::TestCaseGroup* createSpirvIdsAbuseGroup (tcu::TestContext& testCtx)
        return testGroup.release();
 }
 
+tcu::TestCaseGroup* createFunctionParamsGroup (tcu::TestContext& testCtx)
+{
+       de::MovePtr<tcu::TestCaseGroup> testGroup (new tcu::TestCaseGroup(testCtx, "function_params", "Function parameter tests"));
+
+       static const char data_dir[] = "spirv_assembly/instruction/function_params";
+
+       static const struct
+       {
+               const std::string name;
+               const std::string desc;
+       } cases[] =
+       {
+               { "sampler_param", "Test combined image sampler as function parameter" },
+       };
+
+       for (int i = 0; i < DE_LENGTH_OF_ARRAY(cases); ++i)
+       {
+               cts_amber::AmberTestCase *testCase = cts_amber::createAmberTestCase(testCtx,
+                                                                                                                                                       cases[i].name.c_str(),
+                                                                                                                                                       cases[i].desc.c_str(),
+                                                                                                                                                       data_dir,
+                                                                                                                                                       cases[i].name + ".amber");
+               testGroup->addChild(testCase);
+       }
+
+       return testGroup.release();
+}
+
 tcu::TestCaseGroup* createInstructionTests (tcu::TestContext& testCtx)
 {
        const bool testComputePipeline = true;
@@ -20281,6 +20309,7 @@ tcu::TestCaseGroup* createInstructionTests (tcu::TestContext& testCtx)
        instructionTests->addChild(computeTests.release());
        instructionTests->addChild(graphicsTests.release());
        instructionTests->addChild(createSpirvVersion1p4Group(testCtx));
+       instructionTests->addChild(createFunctionParamsGroup(testCtx));
 
        return instructionTests.release();
 }
index d00b836..9fb1cf3 100644 (file)
@@ -324946,6 +324946,7 @@ dEQP-VK.spirv_assembly.instruction.spirv1p4.uconvert.spec_const_opt_truncate_983
 dEQP-VK.spirv_assembly.instruction.spirv1p4.uconvert.spec_const_opt_zero_extend_n4096
 dEQP-VK.spirv_assembly.instruction.spirv1p4.wrap.no_signed_wrap
 dEQP-VK.spirv_assembly.instruction.spirv1p4.wrap.no_unsigned_wrap
+dEQP-VK.spirv_assembly.instruction.function_params.sampler_param
 dEQP-VK.spirv_assembly.type.scalar.i8.negate_vert
 dEQP-VK.spirv_assembly.type.scalar.i8.negate_tessc
 dEQP-VK.spirv_assembly.type.scalar.i8.negate_tesse
index 235f7e8..a293515 100644 (file)
@@ -324946,6 +324946,7 @@ dEQP-VK.spirv_assembly.instruction.spirv1p4.uconvert.spec_const_opt_truncate_983
 dEQP-VK.spirv_assembly.instruction.spirv1p4.uconvert.spec_const_opt_zero_extend_n4096
 dEQP-VK.spirv_assembly.instruction.spirv1p4.wrap.no_signed_wrap
 dEQP-VK.spirv_assembly.instruction.spirv1p4.wrap.no_unsigned_wrap
+dEQP-VK.spirv_assembly.instruction.function_params.sampler_param
 dEQP-VK.spirv_assembly.type.scalar.i8.negate_vert
 dEQP-VK.spirv_assembly.type.scalar.i8.negate_tessc
 dEQP-VK.spirv_assembly.type.scalar.i8.negate_tesse