1 // Copyright 2021 The SwiftShader Authors. All Rights Reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 #include "DrawTester.hpp"
16
17 #include "gmock/gmock.h"
18 #include "gtest/gtest.h"
19
20 class DrawTest : public testing::Test
21 {
22 };
23
24 // Test that a vertex shader with no gl_Position works.
25 // This was fixed in swiftshader-cl/51808
TEST_F(DrawTest,VertexShaderNoPositionOutput)26 TEST_F(DrawTest, VertexShaderNoPositionOutput)
27 {
28 DrawTester tester;
29 tester.onCreateVertexBuffers([](DrawTester &tester) {
30 struct Vertex
31 {
32 float position[3];
33 };
34
35 Vertex vertexBufferData[] = {
36 { { 1.0f, 1.0f, 0.5f } },
37 { { -1.0f, 1.0f, 0.5f } },
38 { { 0.0f, -1.0f, 0.5f } }
39 };
40
41 std::vector<vk::VertexInputAttributeDescription> inputAttributes;
42 inputAttributes.push_back(vk::VertexInputAttributeDescription(0, 0, vk::Format::eR32G32B32Sfloat, offsetof(Vertex, position)));
43
44 tester.addVertexBuffer(vertexBufferData, sizeof(vertexBufferData), std::move(inputAttributes));
45 });
46
47 tester.onCreateVertexShader([](DrawTester &tester) {
48 const char *vertexShader = R"(#version 310 es
49 layout(location = 0) in vec3 inPos;
50
51 void main()
52 {
53 // Remove gl_Position on purpose for the test
54 //gl_Position = vec4(inPos.xyz, 1.0);
55 })";
56
57 return tester.createShaderModule(vertexShader, EShLanguage::EShLangVertex);
58 });
59
60 tester.onCreateFragmentShader([](DrawTester &tester) {
61 const char *fragmentShader = R"(#version 310 es
62 precision highp float;
63
64 layout(location = 0) out vec4 outColor;
65
66 void main()
67 {
68 outColor = vec4(1.0, 1.0, 1.0, 1.0);
69 })";
70
71 return tester.createShaderModule(fragmentShader, EShLanguage::EShLangFragment);
72 });
73
74 tester.initialize();
75 tester.renderFrame();
76 }
77