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