blob: 83bbbfdfb91f4b5f03672cf2245d9a70348eed94 [file] [log] [blame]
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -06001// Copyright 2005, Google Inc.
2// All rights reserved.
3//
4// Redistribution and use in source and binary forms, with or without
5// modification, are permitted provided that the following conditions are
6// met:
7//
8// * Redistributions of source code must retain the above copyright
9// notice, this list of conditions and the following disclaimer.
10// * Redistributions in binary form must reproduce the above
11// copyright notice, this list of conditions and the following disclaimer
12// in the documentation and/or other materials provided with the
13// distribution.
14// * Neither the name of Google Inc. nor the names of its
15// contributors may be used to endorse or promote products derived from
16// this software without specific prior written permission.
17//
18// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
30
31// XGL tests
32//
33// Copyright (C) 2014 LunarG, Inc.
34//
35// Permission is hereby granted, free of charge, to any person obtaining a
36// copy of this software and associated documentation files (the "Software"),
37// to deal in the Software without restriction, including without limitation
38// the rights to use, copy, modify, merge, publish, distribute, sublicense,
39// and/or sell copies of the Software, and to permit persons to whom the
40// Software is furnished to do so, subject to the following conditions:
41//
42// The above copyright notice and this permission notice shall be included
43// in all copies or substantial portions of the Software.
44//
45// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
46// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
47// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
48// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
49// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
50// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
51// DEALINGS IN THE SOFTWARE.
52
53
54// Basic rendering tests
55
56#include <stdlib.h>
57#include <stdio.h>
58#include <stdbool.h>
59#include <string.h>
Courtney Goeltzenleuchter76a643b2014-08-21 17:34:22 -060060#include <iostream>
61#include <fstream>
62using namespace std;
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -060063
64#include <xgl.h>
65#include "gtest-1.7.0/include/gtest/gtest.h"
66
67#include "xgldevice.h"
Courtney Goeltzenleuchter04814f82014-09-01 16:37:18 -060068#include "xglimage.h"
Chia-I Wu4115c892014-08-28 11:56:29 +080069#include "icd-bil.h"
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -060070
Courtney Goeltzenleuchter28029792014-09-04 16:26:02 -060071#include "xgltestframework.h"
Courtney Goeltzenleuchter2268d1e2014-09-01 13:57:15 -060072
Courtney Goeltzenleuchtera948d842014-08-22 16:27:58 -060073//--------------------------------------------------------------------------------------
74// Mesh and VertexFormat Data
75//--------------------------------------------------------------------------------------
76struct Vertex
77{
78 XGL_FLOAT posX, posY, posZ, posW; // Position data
79 XGL_FLOAT r, g, b, a; // Color
80};
81
82#define XYZ1(_x_, _y_, _z_) (_x_), (_y_), (_z_), 1.f
83
84static const Vertex g_vbData[] =
85{
86 { XYZ1( -1, -1, -1 ), XYZ1( 0.f, 0.f, 0.f ) },
87 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
88 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) },
89 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) },
90 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
91 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) },
92
93 { XYZ1( -1, -1, 1 ), XYZ1( 0.f, 0.f, 1.f ) },
94 { XYZ1( -1, 1, 1 ), XYZ1( 0.f, 1.f, 1.f ) },
95 { XYZ1( 1, -1, 1 ), XYZ1( 1.f, 0.f, 1.f ) },
96 { XYZ1( 1, -1, 1 ), XYZ1( 1.f, 0.f, 1.f ) },
97 { XYZ1( -1, 1, 1 ), XYZ1( 0.f, 1.f, 1.f ) },
98 { XYZ1( 1, 1, 1 ), XYZ1( 1.f, 1.f, 1.f ) },
99
100 { XYZ1( 1, 1, 1 ), XYZ1( 1.f, 1.f, 1.f ) },
101 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) },
102 { XYZ1( 1, -1, 1 ), XYZ1( 1.f, 0.f, 1.f ) },
103 { XYZ1( 1, -1, 1 ), XYZ1( 1.f, 0.f, 1.f ) },
104 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) },
105 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
106
107 { XYZ1( -1, 1, 1 ), XYZ1( 0.f, 1.f, 1.f ) },
108 { XYZ1( -1, -1, 1 ), XYZ1( 0.f, 0.f, 1.f ) },
109 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) },
110 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) },
111 { XYZ1( -1, -1, 1 ), XYZ1( 0.f, 0.f, 1.f ) },
112 { XYZ1( -1, -1, -1 ), XYZ1( 0.f, 0.f, 0.f ) },
113
114 { XYZ1( 1, 1, 1 ), XYZ1( 1.f, 1.f, 1.f ) },
115 { XYZ1( -1, 1, 1 ), XYZ1( 0.f, 1.f, 1.f ) },
116 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) },
117 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) },
118 { XYZ1( -1, 1, 1 ), XYZ1( 0.f, 1.f, 1.f ) },
119 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) },
120
121 { XYZ1( 1, -1, 1 ), XYZ1( 1.f, 0.f, 1.f ) },
122 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
123 { XYZ1( -1, -1, 1 ), XYZ1( 0.f, 0.f, 1.f ) },
124 { XYZ1( -1, -1, 1 ), XYZ1( 0.f, 0.f, 1.f ) },
125 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
126 { XYZ1( -1, -1, -1 ), XYZ1( 0.f, 0.f, 0.f ) },
127};
128
Chia-I Wu6e9789c2014-08-30 14:03:32 +0800129static const uint32_t gen6_fs[] = {
130 0x00600001, 0x202003fe, 0x00000000, 0x3f800000, // mov(8) m1<1>F 1F { align1 1Q };
131 0x00600001, 0x204003fe, 0x00000000, 0x00000000, // mov(8) m2<1>F 0F { align1 1Q };
132 0x00600001, 0x206003fe, 0x00000000, 0x00000000, // mov(8) m3<1>F 0F { align1 1Q };
133 0x00600001, 0x208003fe, 0x00000000, 0x3f800000, // mov(8) m4<1>F 1F { align1 1Q };
134 0x05600032, 0x20001fc8, 0x008d0020, 0x88019400, // sendc(8) null m1<8,8,1>F
135 // render RT write SIMD8 LastRT Surface = 0 mlen 4 rlen 0 { align1 1Q EOT };
136};
137
138static const uint32_t gen6_vs[] = {
139 0x01600110, 0x200f1ca4, 0x00600020, 0x00000000, // cmp.z.f0(8) null g1<4,4,1>.xD 0D { align16 1Q };
140 0x00670122, 0x000a108f, 0x000e0004, 0x000e0004, // (+f0.all4h) if(8) JIP: 10 { align16 1Q };
141 0x00600501, 0x204303fd, 0x00000000, 0xbf800000, // mov(8) g2<1>.xyF -1F { align16 NoDDClr 1Q };
142 0x00600d01, 0x204403fd, 0x00000000, 0x00000000, // mov(8) g2<1>.zF 0F { align16 NoDDClr,NoDDChk 1Q };
143 0x00600901, 0x204803fd, 0x00000000, 0x3f800000, // mov(8) g2<1>.wF 1F { align16 NoDDChk 1Q };
144 0x00600124, 0x0014108f, 0x006e0004, 0x006e0004, // else(8) JIP: 20 { align16 1Q };
145 0x01600110, 0x200f1ca4, 0x00600020, 0x00000001, // cmp.z.f0(8) null g1<4,4,1>.xD 1D { align16 1Q };
146 0x00670122, 0x000a108f, 0x000e0004, 0x000e0004, // (+f0.all4h) if(8) JIP: 10 { align16 1Q };
147 0x00600501, 0x204903fd, 0x00000000, 0x3f800000, // mov(8) g2<1>.xwF 1F { align16 NoDDClr 1Q };
148 0x00600d01, 0x204203fd, 0x00000000, 0xbf800000, // mov(8) g2<1>.yF -1F { align16 NoDDClr,NoDDChk 1Q };
149 0x00600901, 0x204403fd, 0x00000000, 0x00000000, // mov(8) g2<1>.zF 0F { align16 NoDDChk 1Q };
150 0x00600124, 0x0006108f, 0x006e0004, 0x006e0004, // else(8) JIP: 6 { align16 1Q };
151 0x00600501, 0x204503fd, 0x00000000, 0x00000000, // mov(8) g2<1>.xzF 0F { align16 NoDDClr 1Q };
152 0x00600901, 0x204a03fd, 0x00000000, 0x3f800000, // mov(8) g2<1>.ywF 1F { align16 NoDDChk 1Q };
153 0x00600125, 0x0002108f, 0x006e0004, 0x006e0002, // endif(8) JIP: 2 { align16 1Q };
154 0x00600125, 0x0002108f, 0x006e0004, 0x006e0002, // endif(8) JIP: 2 { align16 1Q };
155 0x00600101, 0x204f0062, 0x00000000, 0x00000000, // mov(8) m2<1>UD 0x00000000UD { align16 1Q };
156 0x00600101, 0x206f03be, 0x006e0044, 0x00000000, // mov(8) m3<1>F g2<4,4,1>F { align16 1Q };
157 0x00600301, 0x202f0022, 0x006e0004, 0x00000000, // mov(8) m1<1>UD g0<4,4,1>UD { align16 WE_all 1Q };
158 0x06600131, 0x200f1fdc, 0x006e0024, 0x8608c400, // send(8) null m1<4,4,1>F
159 // urb 0 urb_write interleave used complete mlen 3 rlen 0 { align16 1Q EOT };
160};
161
162static const uint32_t gen7_fs[] = {
163 0x00600001, 0x2e2003fd, 0x00000000, 0x3f800000, // mov(8) g113<1>F 1F { align1 1Q };
164 0x00600001, 0x2e4003fd, 0x00000000, 0x00000000, // mov(8) g114<1>F 0F { align1 1Q };
165 0x00600001, 0x2e6003fd, 0x00000000, 0x00000000, // mov(8) g115<1>F 0F { align1 1Q };
166 0x00600001, 0x2e8003fd, 0x00000000, 0x3f800000, // mov(8) g116<1>F 1F { align1 1Q };
167 0x05600032, 0x20001fa8, 0x008d0e20, 0x88031400, // sendc(8) null g113<8,8,1>F
168 // render RT write SIMD8 LastRT Surface = 0 mlen 4 rlen 0 { align1 1Q EOT };
169};
170
171static const uint32_t gen7_vs[] = {
172 0x01608110, 0x200f1ca4, 0x00600020, 0x00000000, // cmp.z.f0(8) null g1<4,4,1>.xD 0D { align16 1Q switch };
173 0x00670122, 0x200f0c84, 0x000e0004, 0x001c000a, // (+f0.all4h) if(8) JIP: 10 UIP: 28 { align16 1Q };
174 0x00600501, 0x204303fd, 0x00000000, 0xbf800000, // mov(8) g2<1>.xyF -1F { align16 NoDDClr 1Q };
175 0x00600d01, 0x204403fd, 0x00000000, 0x00000000, // mov(8) g2<1>.zF 0F { align16 NoDDClr,NoDDChk 1Q };
176 0x00600901, 0x204803fd, 0x00000000, 0x3f800000, // mov(8) g2<1>.wF 1F { align16 NoDDChk 1Q };
177 0x00600124, 0x200f0c84, 0x006e0004, 0x00000014, // else(8) JIP: 20 { align16 1Q };
178 0x01608110, 0x200f1ca4, 0x00600020, 0x00000001, // cmp.z.f0(8) null g1<4,4,1>.xD 1D { align16 1Q switch };
179 0x00670122, 0x200f0c84, 0x000e0004, 0x000e000a, // (+f0.all4h) if(8) JIP: 10 UIP: 14 { align16 1Q };
180 0x00600501, 0x204903fd, 0x00000000, 0x3f800000, // mov(8) g2<1>.xwF 1F { align16 NoDDClr 1Q };
181 0x00600d01, 0x204203fd, 0x00000000, 0xbf800000, // mov(8) g2<1>.yF -1F { align16 NoDDClr,NoDDChk 1Q };
182 0x00600901, 0x204403fd, 0x00000000, 0x00000000, // mov(8) g2<1>.zF 0F { align16 NoDDChk 1Q };
183 0x00600124, 0x200f0c84, 0x006e0004, 0x00000006, // else(8) JIP: 6 { align16 1Q };
184 0x00600501, 0x204503fd, 0x00000000, 0x00000000, // mov(8) g2<1>.xzF 0F { align16 NoDDClr 1Q };
185 0x00600901, 0x204a03fd, 0x00000000, 0x3f800000, // mov(8) g2<1>.ywF 1F { align16 NoDDChk 1Q };
186 0x00600125, 0x200f0c84, 0x006e0004, 0x00000002, // endif(8) JIP: 2 { align16 1Q };
187 0x00600125, 0x200f0c84, 0x006e0004, 0x00000002, // endif(8) JIP: 2 { align16 1Q };
188 0x00600101, 0x2e4f0061, 0x00000000, 0x00000000, // mov(8) g114<1>UD 0x00000000UD { align16 1Q };
189 0x00600101, 0x2e6f03bd, 0x006e0044, 0x00000000, // mov(8) g115<1>F g2<4,4,1>F { align16 1Q };
190 0x00600301, 0x2e2f0021, 0x006e0004, 0x00000000, // mov(8) g113<1>UD g0<4,4,1>UD { align16 WE_all 1Q };
191 0x00000206, 0x2e340c21, 0x00000014, 0x0000ff00, // or(1) g113.5<1>UD g0.5<0,1,0>UD 0x0000ff00UD { align1 WE_all };
192 0x06600131, 0x200f1fbc, 0x006e0e24, 0x8608c000, // send(8) null g113<4,4,1>F
193 // urb 0 write HWord interleave complete mlen 3 rlen 0 { align16 1Q EOT };
194};
Courtney Goeltzenleuchtera948d842014-08-22 16:27:58 -0600195
Courtney Goeltzenleuchter28029792014-09-04 16:26:02 -0600196class XglRenderTest : public XglTestFramework
197{
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600198public:
Chia-I Wua3b9d6a2014-08-30 23:53:01 +0800199 void CreateQueryPool(XGL_QUERY_TYPE type, XGL_UINT slots,
200 XGL_QUERY_POOL *pPool, XGL_GPU_MEMORY *pMem);
201 void DestroyQueryPool(XGL_QUERY_POOL pool, XGL_GPU_MEMORY mem);
202
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600203 XGL_DEVICE device() {return m_device->device();}
Chia-I Wu6e9789c2014-08-30 14:03:32 +0800204 void CreateShader(XGL_PIPELINE_SHADER_STAGE stage, XGL_SHADER *pshader);
Courtney Goeltzenleuchterac8bd172014-08-20 15:28:00 -0600205 void InitPipeline();
Courtney Goeltzenleuchtera948d842014-08-22 16:27:58 -0600206 void InitMesh( XGL_UINT32 numVertices, XGL_GPU_SIZE vbStride, const void* vertices );
207 void DrawTriangleTest();
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600208
209protected:
210 XGL_APPLICATION_INFO app_info;
211 XGL_PHYSICAL_GPU objs[MAX_GPUS];
212 XGL_UINT gpu_count;
Courtney Goeltzenleuchtera948d842014-08-22 16:27:58 -0600213 XGL_GPU_MEMORY m_descriptor_set_mem;
214 XGL_GPU_MEMORY m_pipe_mem;
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600215 XglDevice *m_device;
Courtney Goeltzenleuchterac8bd172014-08-20 15:28:00 -0600216 XGL_CMD_BUFFER m_cmdBuffer;
Courtney Goeltzenleuchtera948d842014-08-22 16:27:58 -0600217 XGL_UINT32 m_numVertices;
218 XGL_MEMORY_VIEW_ATTACH_INFO m_vtxBufferView;
219 XGL_GPU_MEMORY m_vtxBufferMem;
220 XGL_UINT32 m_numMemRefs;
221 XGL_MEMORY_REF m_memRefs[5];
222 XGL_RASTER_STATE_OBJECT m_stateRaster;
Courtney Goeltzenleuchter68cfe612014-08-26 18:16:41 -0600223 XGL_COLOR_BLEND_STATE_OBJECT m_colorBlend;
Courtney Goeltzenleuchtera948d842014-08-22 16:27:58 -0600224 XGL_VIEWPORT_STATE_OBJECT m_stateViewport;
225 XGL_DEPTH_STENCIL_STATE_OBJECT m_stateDepthStencil;
226 XGL_MSAA_STATE_OBJECT m_stateMsaa;
227 XGL_DESCRIPTOR_SET m_rsrcDescSet;
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600228
229 virtual void SetUp() {
230 XGL_RESULT err;
231
232 this->app_info.sType = XGL_STRUCTURE_TYPE_APPLICATION_INFO;
233 this->app_info.pNext = NULL;
234 this->app_info.pAppName = (const XGL_CHAR *) "base";
235 this->app_info.appVersion = 1;
236 this->app_info.pEngineName = (const XGL_CHAR *) "unittest";
237 this->app_info.engineVersion = 1;
238 this->app_info.apiVersion = XGL_MAKE_VERSION(0, 22, 0);
239
Courtney Goeltzenleuchtera948d842014-08-22 16:27:58 -0600240 memset(&m_vtxBufferView, 0, sizeof(m_vtxBufferView));
241 m_vtxBufferView.sType = XGL_STRUCTURE_TYPE_MEMORY_VIEW_ATTACH_INFO;
242
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600243 err = xglInitAndEnumerateGpus(&app_info, NULL,
244 MAX_GPUS, &this->gpu_count, objs);
245 ASSERT_XGL_SUCCESS(err);
246 ASSERT_GE(1, this->gpu_count) << "No GPU available";
247
248 m_device = new XglDevice(0, objs[0]);
249 m_device->get_device_queue();
250 }
251
252 virtual void TearDown() {
253 xglInitAndEnumerateGpus(&this->app_info, XGL_NULL_HANDLE, 0, &gpu_count, XGL_NULL_HANDLE);
254 }
255};
256
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600257
Chia-I Wua3b9d6a2014-08-30 23:53:01 +0800258void XglRenderTest::CreateQueryPool(XGL_QUERY_TYPE type, XGL_UINT slots,
259 XGL_QUERY_POOL *pPool, XGL_GPU_MEMORY *pMem)
260{
261 XGL_RESULT err;
262
263 XGL_QUERY_POOL_CREATE_INFO poolCreateInfo = {};
264 poolCreateInfo.sType = XGL_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
265 poolCreateInfo.pNext = NULL;
266 poolCreateInfo.queryType = type;
267 poolCreateInfo.slots = slots;
268
269 err = xglCreateQueryPool(device(), &poolCreateInfo, pPool);
270 ASSERT_XGL_SUCCESS(err);
271
272 XGL_MEMORY_REQUIREMENTS mem_req;
273 XGL_UINT data_size;
274 err = xglGetObjectInfo(*pPool, XGL_INFO_TYPE_MEMORY_REQUIREMENTS,
275 &data_size, &mem_req);
276 ASSERT_XGL_SUCCESS(err);
277 ASSERT_EQ(data_size, sizeof(mem_req));
278
279 if (!mem_req.size) {
280 *pMem = XGL_NULL_HANDLE;
281 return;
282 }
283
284 XGL_MEMORY_ALLOC_INFO mem_info;
285
286 memset(&mem_info, 0, sizeof(mem_info));
287 mem_info.sType = XGL_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
288 mem_info.allocationSize = mem_req.size;
289 mem_info.alignment = mem_req.alignment;
290 mem_info.heapCount = mem_req.heapCount;
291 memcpy(mem_info.heaps, mem_req.heaps, sizeof(XGL_UINT)*XGL_MAX_MEMORY_HEAPS);
292 mem_info.memPriority = XGL_MEMORY_PRIORITY_NORMAL;
293 mem_info.flags = XGL_MEMORY_ALLOC_SHAREABLE_BIT;
294 err = xglAllocMemory(device(), &mem_info, pMem);
295 ASSERT_XGL_SUCCESS(err);
296
297 err = xglBindObjectMemory(*pPool, *pMem, 0);
298 ASSERT_XGL_SUCCESS(err);
299}
300
301void XglRenderTest::DestroyQueryPool(XGL_QUERY_POOL pool, XGL_GPU_MEMORY mem)
302{
303 ASSERT_XGL_SUCCESS(xglBindObjectMemory(pool, XGL_NULL_HANDLE, 0));
304 ASSERT_XGL_SUCCESS(xglFreeMemory(mem));
305 ASSERT_XGL_SUCCESS(xglDestroyObject(pool));
306}
307
Chia-I Wu6e9789c2014-08-30 14:03:32 +0800308void XglRenderTest::CreateShader(XGL_PIPELINE_SHADER_STAGE stage, XGL_SHADER *pshader)
Courtney Goeltzenleuchterac8bd172014-08-20 15:28:00 -0600309{
Chia-I Wu4b7b4582014-08-28 12:27:21 +0800310 struct icd_bil_header *pBIL;
Courtney Goeltzenleuchter76a643b2014-08-21 17:34:22 -0600311 char * memblock;
Chia-I Wu6e9789c2014-08-30 14:03:32 +0800312 const char *kernel;
313 size_t kernel_size;
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600314 XGL_RESULT err;
315
Chia-I Wu6e9789c2014-08-30 14:03:32 +0800316 const XGL_PHYSICAL_GPU_PROPERTIES *props = &m_device->props;
317 const int gen = (strstr((const char *) props->gpuName, "Sandybridge")) ? 6 : 7;
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600318
Chia-I Wu6e9789c2014-08-30 14:03:32 +0800319 if (stage == XGL_SHADER_STAGE_VERTEX) {
320 if (gen == 6) {
321 kernel = (const char *) gen6_vs;
322 kernel_size = sizeof(gen6_vs);
323 } else {
324 kernel = (const char *) gen7_vs;
325 kernel_size = sizeof(gen7_vs);
326 }
327 } else {
328 if (gen == 6) {
329 kernel = (const char *) gen6_fs;
330 kernel_size = sizeof(gen6_fs);
331 } else {
332 kernel = (const char *) gen7_fs;
333 kernel_size = sizeof(gen7_fs);
334 }
335 }
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600336
Chia-I Wu6e9789c2014-08-30 14:03:32 +0800337 memblock = new char [sizeof(*pBIL) + kernel_size];
Courtney Goeltzenleuchtera948d842014-08-22 16:27:58 -0600338 ASSERT_TRUE(memblock != NULL) << "memory allocation failed";
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600339
Chia-I Wu4b7b4582014-08-28 12:27:21 +0800340 pBIL = (struct icd_bil_header *) memblock;
341 pBIL->magic = ICD_BIL_MAGIC;
342 pBIL->version = ICD_BIL_VERSION;
343
Chia-I Wu6e9789c2014-08-30 14:03:32 +0800344 pBIL->gen_magic = (stage == XGL_SHADER_STAGE_VERTEX) ? 'v' : 'w';
345 memcpy(pBIL + 1, kernel, kernel_size);
Chia-I Wu4b7b4582014-08-28 12:27:21 +0800346
Courtney Goeltzenleuchtera948d842014-08-22 16:27:58 -0600347 XGL_SHADER_CREATE_INFO createInfo;
348 XGL_SHADER shader;
Courtney Goeltzenleuchter76a643b2014-08-21 17:34:22 -0600349
Courtney Goeltzenleuchtera948d842014-08-22 16:27:58 -0600350 createInfo.sType = XGL_STRUCTURE_TYPE_SHADER_CREATE_INFO;
351 createInfo.pNext = NULL;
352 createInfo.pCode = memblock;
Chia-I Wu6e9789c2014-08-30 14:03:32 +0800353 createInfo.codeSize = sizeof(*pBIL) + kernel_size;
Courtney Goeltzenleuchtera948d842014-08-22 16:27:58 -0600354 createInfo.flags = 0;
355 err = xglCreateShader(device(), &createInfo, &shader);
356 ASSERT_XGL_SUCCESS(err);
Courtney Goeltzenleuchter76a643b2014-08-21 17:34:22 -0600357
Courtney Goeltzenleuchtera948d842014-08-22 16:27:58 -0600358 delete[] memblock;
Courtney Goeltzenleuchter76a643b2014-08-21 17:34:22 -0600359
Courtney Goeltzenleuchtera948d842014-08-22 16:27:58 -0600360 *pshader = shader;
Courtney Goeltzenleuchterac8bd172014-08-20 15:28:00 -0600361}
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600362
Courtney Goeltzenleuchtera948d842014-08-22 16:27:58 -0600363// this function will create the vertex buffer and fill it with the mesh data
364void XglRenderTest::InitMesh( XGL_UINT32 numVertices, XGL_GPU_SIZE vbStride,
365 const void* vertices )
366{
367 XGL_RESULT err = XGL_SUCCESS;
368
369 assert( numVertices * vbStride > 0 );
370 m_numVertices = numVertices;
371
372 XGL_MEMORY_ALLOC_INFO alloc_info = {};
373 XGL_UINT8 *pData;
374
375 alloc_info.sType = XGL_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
376 alloc_info.allocationSize = numVertices * vbStride;
377 alloc_info.alignment = 0;
378 alloc_info.heapCount = 1;
379 alloc_info.heaps[0] = 0; // TODO: Use known existing heap
380
381 alloc_info.flags = XGL_MEMORY_HEAP_CPU_VISIBLE_BIT;
382 alloc_info.memPriority = XGL_MEMORY_PRIORITY_NORMAL;
383
384 err = xglAllocMemory(device(), &alloc_info, &m_vtxBufferMem);
385 ASSERT_XGL_SUCCESS(err);
386
387 err = xglMapMemory(m_vtxBufferMem, 0, (XGL_VOID **) &pData);
388 ASSERT_XGL_SUCCESS(err);
389
390 memcpy(pData, vertices, alloc_info.allocationSize);
391
392 err = xglUnmapMemory(m_vtxBufferMem);
393 ASSERT_XGL_SUCCESS(err);
394
395 // set up the memory view for the vertex buffer
396 this->m_vtxBufferView.stride = vbStride;
397 this->m_vtxBufferView.range = numVertices * vbStride;
398 this->m_vtxBufferView.offset = 0;
399 this->m_vtxBufferView.mem = m_vtxBufferMem;
400 this->m_vtxBufferView.format.channelFormat = XGL_CH_FMT_UNDEFINED;
401 this->m_vtxBufferView.format.numericFormat = XGL_NUM_FMT_UNDEFINED;
402
403 // open the command buffer
404 err = xglBeginCommandBuffer( m_cmdBuffer, 0 );
405 ASSERT_XGL_SUCCESS(err);
406
407 XGL_MEMORY_STATE_TRANSITION transition = {};
408 transition.mem = m_vtxBufferMem;
409 transition.oldState = XGL_MEMORY_STATE_DATA_TRANSFER;
410 transition.newState = XGL_MEMORY_STATE_GRAPHICS_SHADER_READ_ONLY;
411 transition.offset = 0;
412 transition.regionSize = numVertices * vbStride;
413
414 // write transition to the command buffer
415 xglCmdPrepareMemoryRegions( m_cmdBuffer, 1, &transition );
416 this->m_vtxBufferView.state = XGL_MEMORY_STATE_GRAPHICS_SHADER_READ_ONLY;
417
418 // finish recording the command buffer
419 err = xglEndCommandBuffer( m_cmdBuffer );
420 ASSERT_XGL_SUCCESS(err);
421
422 // this command buffer only uses the vertex buffer memory
423 m_numMemRefs = 1;
424 m_memRefs[0].flags = 0;
425 m_memRefs[0].mem = m_vtxBufferMem;
426
427 // submit the command buffer to the universal queue
428 err = xglQueueSubmit( m_device->m_queue, 1, &m_cmdBuffer, m_numMemRefs, m_memRefs, NULL );
429 ASSERT_XGL_SUCCESS(err);
430}
431
432void XglRenderTest::DrawTriangleTest()
433{
Courtney Goeltzenleuchterac8bd172014-08-20 15:28:00 -0600434 XGL_RESULT err;
435 XGL_GRAPHICS_PIPELINE_CREATE_INFO info = {};
436 XGL_SHADER vs, ps;
437 XGL_PIPELINE_SHADER_STAGE_CREATE_INFO vs_stage;
438 XGL_PIPELINE_SHADER_STAGE_CREATE_INFO ps_stage;
439 XGL_PIPELINE pipeline;
Courtney Goeltzenleuchtera948d842014-08-22 16:27:58 -0600440 int width = 256, height = 256;
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600441
Courtney Goeltzenleuchtera948d842014-08-22 16:27:58 -0600442 // create a raster state (solid, back-face culling)
443 XGL_RASTER_STATE_CREATE_INFO raster = {};
444 raster.sType = XGL_STRUCTURE_TYPE_RASTER_STATE_CREATE_INFO;
445 raster.fillMode = XGL_FILL_SOLID;
Chia-I Wu0059c372014-08-31 00:52:42 +0800446 raster.cullMode = XGL_CULL_NONE;
Courtney Goeltzenleuchtera948d842014-08-22 16:27:58 -0600447 raster.frontFace = XGL_FRONT_FACE_CCW;
448 err = xglCreateRasterState( device(), &raster, &m_stateRaster );
449 ASSERT_XGL_SUCCESS(err);
450
451 XGL_VIEWPORT_STATE_CREATE_INFO viewport = {};
452 viewport.viewportCount = 1;
453 viewport.scissorEnable = XGL_FALSE;
454 viewport.viewports[0].originX = 0;
455 viewport.viewports[0].originY = 0;
456 viewport.viewports[0].width = 1.f * width;
457 viewport.viewports[0].height = 1.f * height;
458 viewport.viewports[0].minDepth = 0.f;
459 viewport.viewports[0].maxDepth = 1.f;
460
461 err = xglCreateViewportState( device(), &viewport, &m_stateViewport );
462 ASSERT_XGL_SUCCESS( err );
463
Courtney Goeltzenleuchter68cfe612014-08-26 18:16:41 -0600464 XGL_COLOR_BLEND_STATE_CREATE_INFO blend = {};
465 blend.sType = XGL_STRUCTURE_TYPE_COLOR_BLEND_STATE_CREATE_INFO;
466 err = xglCreateColorBlendState(device(), &blend, &m_colorBlend);
467 ASSERT_XGL_SUCCESS( err );
468
Courtney Goeltzenleuchtera948d842014-08-22 16:27:58 -0600469 XGL_DEPTH_STENCIL_STATE_CREATE_INFO depthStencil = {};
470 depthStencil.sType = XGL_STRUCTURE_TYPE_DEPTH_STENCIL_STATE_CREATE_INFO;
471 depthStencil.depthTestEnable = XGL_FALSE;
472 depthStencil.depthWriteEnable = XGL_FALSE;
473 depthStencil.depthFunc = XGL_COMPARE_LESS_EQUAL;
474 depthStencil.depthBoundsEnable = XGL_FALSE;
475 depthStencil.minDepth = 0.f;
476 depthStencil.maxDepth = 1.f;
477 depthStencil.back.stencilDepthFailOp = XGL_STENCIL_OP_KEEP;
478 depthStencil.back.stencilFailOp = XGL_STENCIL_OP_KEEP;
479 depthStencil.back.stencilPassOp = XGL_STENCIL_OP_KEEP;
480 depthStencil.back.stencilRef = 0x00;
481 depthStencil.back.stencilFunc = XGL_COMPARE_ALWAYS;
482 depthStencil.front = depthStencil.back;
483
484 err = xglCreateDepthStencilState( device(), &depthStencil, &m_stateDepthStencil );
485 ASSERT_XGL_SUCCESS( err );
486
487 XGL_MSAA_STATE_CREATE_INFO msaa = {};
488 msaa.sType = XGL_STRUCTURE_TYPE_MSAA_STATE_CREATE_INFO;
489 msaa.sampleMask = 1;
490 msaa.samples = 1;
491
492 err = xglCreateMsaaState( device(), &msaa, &m_stateMsaa );
493 ASSERT_XGL_SUCCESS( err );
494
495 XGL_CMD_BUFFER_CREATE_INFO cmdInfo = {};
496
497 cmdInfo.sType = XGL_STRUCTURE_TYPE_CMD_BUFFER_CREATE_INFO;
498 cmdInfo.queueType = XGL_QUEUE_TYPE_GRAPHICS;
499 err = xglCreateCommandBuffer(device(), &cmdInfo, &m_cmdBuffer);
500 ASSERT_XGL_SUCCESS(err) << "xglCreateCommandBuffer failed";
501
Courtney Goeltzenleuchter04814f82014-09-01 16:37:18 -0600502 XglImage *renderTarget;
503 XGL_FORMAT fmt = {
504 XGL_CH_FMT_R8G8B8A8,
505 XGL_NUM_FMT_UNORM
506 };
507 ASSERT_NO_FATAL_FAILURE(m_device->CreateImage(width, height, fmt,
508 XGL_IMAGE_USAGE_SHADER_ACCESS_WRITE_BIT |
509 XGL_IMAGE_USAGE_COLOR_ATTACHMENT_BIT,
510 &renderTarget));
Courtney Goeltzenleuchtera948d842014-08-22 16:27:58 -0600511
512#if 0
513 // Create descriptor set for our one resource
514 XGL_DESCRIPTOR_SET_CREATE_INFO descriptorInfo = {};
515 descriptorInfo.sType = XGL_STRUCTURE_TYPE_DESCRIPTOR_SET_CREATE_INFO;
516 descriptorInfo.slots = 1; // Vertex buffer only
517
518 // create a descriptor set with a single slot
519 err = xglCreateDescriptorSet( device(), &descriptorInfo, &m_rsrcDescSet );
520 ASSERT_XGL_SUCCESS(err) << "xglCreateDescriptorSet failed";
521
522 // bind memory to the descriptor set
523 err = m_device->AllocAndBindGpuMemory(m_rsrcDescSet, "DescriptorSet", &m_descriptor_set_mem);
524
525 // set up the memory view for the vertex buffer
526 this->m_vtxBufferView.stride = vbStride;
527 this->m_vtxBufferView.range = numVertices * vbStride;
528 this->m_vtxBufferView.offset = 0;
529 this->m_vtxBufferView.mem = m_vtxBufferMem;
530 this->m_vtxBufferView.format.channelFormat = XGL_CH_FMT_UNDEFINED;
531 this->m_vtxBufferView.format.numericFormat = XGL_NUM_FMT_UNDEFINED;
532 // write the vertex buffer view to the descriptor set
533 xglBeginDescriptorSetUpdate( m_rsrcDescSet );
534 xglAttachMemoryViewDescriptors( m_rsrcDescSet, 0, 1, &m_vtxBufferView );
535 xglEndDescriptorSetUpdate( m_rsrcDescSet );
536#endif
Courtney Goeltzenleuchterac8bd172014-08-20 15:28:00 -0600537
Chia-I Wu6e9789c2014-08-30 14:03:32 +0800538 ASSERT_NO_FATAL_FAILURE(CreateShader(XGL_SHADER_STAGE_VERTEX, &vs));
Courtney Goeltzenleuchterac8bd172014-08-20 15:28:00 -0600539
540 vs_stage.sType = XGL_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
541 vs_stage.pNext = XGL_NULL_HANDLE;
542 vs_stage.shader.stage = XGL_SHADER_STAGE_VERTEX;
543 vs_stage.shader.shader = vs;
Chia-I Wu3c89e4e2014-08-23 17:47:45 +0800544 vs_stage.shader.descriptorSetMapping[0].descriptorCount = 0;
Courtney Goeltzenleuchterac8bd172014-08-20 15:28:00 -0600545 vs_stage.shader.linkConstBufferCount = 0;
546 vs_stage.shader.pLinkConstBufferInfo = XGL_NULL_HANDLE;
Chia-I Wu3c89e4e2014-08-23 17:47:45 +0800547 vs_stage.shader.dynamicMemoryViewMapping.slotObjectType = XGL_SLOT_UNUSED;
Courtney Goeltzenleuchterac8bd172014-08-20 15:28:00 -0600548 vs_stage.shader.dynamicMemoryViewMapping.shaderEntityIndex = 0;
549
Chia-I Wu6e9789c2014-08-30 14:03:32 +0800550 ASSERT_NO_FATAL_FAILURE(CreateShader(XGL_SHADER_STAGE_FRAGMENT, &ps));
Courtney Goeltzenleuchterac8bd172014-08-20 15:28:00 -0600551
552 ps_stage.sType = XGL_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
553 ps_stage.pNext = &vs_stage;
554 ps_stage.shader.stage = XGL_SHADER_STAGE_FRAGMENT;
555 ps_stage.shader.shader = ps;
Courtney Goeltzenleuchterac8bd172014-08-20 15:28:00 -0600556 // TODO: Do we need a descriptor set mapping for fragment?
Chia-I Wu3c89e4e2014-08-23 17:47:45 +0800557 ps_stage.shader.descriptorSetMapping[0].descriptorCount = 0;
Courtney Goeltzenleuchterac8bd172014-08-20 15:28:00 -0600558 ps_stage.shader.linkConstBufferCount = 0;
559 ps_stage.shader.pLinkConstBufferInfo = XGL_NULL_HANDLE;
Chia-I Wu3c89e4e2014-08-23 17:47:45 +0800560 ps_stage.shader.dynamicMemoryViewMapping.slotObjectType = XGL_SLOT_UNUSED;
Courtney Goeltzenleuchterac8bd172014-08-20 15:28:00 -0600561 ps_stage.shader.dynamicMemoryViewMapping.shaderEntityIndex = 0;
562
563 XGL_PIPELINE_IA_STATE_CREATE_INFO ia_state = {
564 XGL_STRUCTURE_TYPE_PIPELINE_IA_STATE_CREATE_INFO, // sType
565 &ps_stage, // pNext
566 XGL_TOPOLOGY_TRIANGLE_LIST, // XGL_PRIMITIVE_TOPOLOGY
567 XGL_FALSE, // disableVertexReuse
568 XGL_PROVOKING_VERTEX_LAST, // XGL_PROVOKING_VERTEX_CONVENTION
569 XGL_FALSE, // primitiveRestartEnable
570 0 // primitiveRestartIndex
571 };
572
573 XGL_PIPELINE_RS_STATE_CREATE_INFO rs_state = {
574 XGL_STRUCTURE_TYPE_PIPELINE_RS_STATE_CREATE_INFO,
575 &ia_state,
576 XGL_FALSE, // depthClipEnable
577 XGL_FALSE, // rasterizerDiscardEnable
578 1.0 // pointSize
579 };
580
581 XGL_PIPELINE_CB_STATE cb_state = {
582 XGL_STRUCTURE_TYPE_PIPELINE_CB_STATE_CREATE_INFO,
583 &rs_state,
584 XGL_FALSE, // alphaToCoverageEnable
585 XGL_FALSE, // dualSourceBlendEnable
586 XGL_LOGIC_OP_COPY, // XGL_LOGIC_OP
587 { // XGL_PIPELINE_CB_ATTACHMENT_STATE
588 {
589 XGL_FALSE, // blendEnable
Chia-I Wuf5d5c1a2014-08-27 15:02:10 +0800590 {XGL_CH_FMT_R8G8B8A8, XGL_NUM_FMT_UNORM}, // XGL_FORMAT
Courtney Goeltzenleuchterac8bd172014-08-20 15:28:00 -0600591 0xF // channelWriteMask
592 }
593 }
594 };
595
596 // TODO: Should take depth buffer format from queried formats
597 XGL_PIPELINE_DB_STATE_CREATE_INFO db_state = {
598 XGL_STRUCTURE_TYPE_PIPELINE_DB_STATE_CREATE_INFO,
599 &cb_state,
600 {XGL_CH_FMT_R32, XGL_NUM_FMT_DS} // XGL_FORMAT
601 };
602
603 info.sType = XGL_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
604 info.pNext = &db_state;
605 info.flags = 0;
606 err = xglCreateGraphicsPipeline(device(), &info, &pipeline);
607 ASSERT_XGL_SUCCESS(err);
608
Courtney Goeltzenleuchtera948d842014-08-22 16:27:58 -0600609 err = m_device->AllocAndBindGpuMemory(pipeline, "Pipeline", &m_pipe_mem);
Courtney Goeltzenleuchter76a643b2014-08-21 17:34:22 -0600610 ASSERT_XGL_SUCCESS(err);
611
612 /*
613 * Shaders are now part of the pipeline, don't need these anymore
614 */
Courtney Goeltzenleuchterac8bd172014-08-20 15:28:00 -0600615 ASSERT_XGL_SUCCESS(xglDestroyObject(ps));
616 ASSERT_XGL_SUCCESS(xglDestroyObject(vs));
Courtney Goeltzenleuchter76a643b2014-08-21 17:34:22 -0600617
Chia-I Wuf070ec12014-08-30 23:58:36 +0800618 XGL_QUERY_POOL query;
619 XGL_GPU_MEMORY query_mem;
620 ASSERT_NO_FATAL_FAILURE(CreateQueryPool(XGL_QUERY_PIPELINE_STATISTICS, 1, &query, &query_mem));
621
Courtney Goeltzenleuchtera948d842014-08-22 16:27:58 -0600622 // Build command buffer
623 err = xglBeginCommandBuffer(m_cmdBuffer, 0);
624 ASSERT_XGL_SUCCESS(err);
625
626 // whatever we want to do, we do it to the whole buffer
627 XGL_IMAGE_SUBRESOURCE_RANGE srRange = {};
628 srRange.aspect = XGL_IMAGE_ASPECT_COLOR;
629 srRange.baseMipLevel = 0;
630 srRange.mipLevels = XGL_LAST_MIP_OR_SLICE;
631 srRange.baseArraySlice = 0;
632 srRange.arraySize = XGL_LAST_MIP_OR_SLICE;
633
634 // prepare the whole back buffer for clear
635 XGL_IMAGE_STATE_TRANSITION transitionToClear = {};
Courtney Goeltzenleuchter04814f82014-09-01 16:37:18 -0600636 transitionToClear.image = renderTarget->image();
637 transitionToClear.oldState = renderTarget->state();
Courtney Goeltzenleuchtera948d842014-08-22 16:27:58 -0600638 transitionToClear.newState = XGL_IMAGE_STATE_CLEAR;
639 transitionToClear.subresourceRange = srRange;
640 xglCmdPrepareImages( m_cmdBuffer, 1, &transitionToClear );
Courtney Goeltzenleuchter04814f82014-09-01 16:37:18 -0600641 renderTarget->state(( XGL_IMAGE_STATE ) transitionToClear.newState);
Courtney Goeltzenleuchtera948d842014-08-22 16:27:58 -0600642
643 // clear the back buffer to dark grey
644 XGL_UINT clearColor[4] = {64, 64, 64, 0};
Courtney Goeltzenleuchter04814f82014-09-01 16:37:18 -0600645 xglCmdClearColorImageRaw( m_cmdBuffer, renderTarget->image(), clearColor, 1, &srRange );
Courtney Goeltzenleuchtera948d842014-08-22 16:27:58 -0600646
647 // prepare back buffer for rendering
648 XGL_IMAGE_STATE_TRANSITION transitionToRender = {};
Courtney Goeltzenleuchter04814f82014-09-01 16:37:18 -0600649 transitionToRender.image = renderTarget->image();
650 transitionToRender.oldState = renderTarget->state();
Courtney Goeltzenleuchtera948d842014-08-22 16:27:58 -0600651 transitionToRender.newState = XGL_IMAGE_STATE_TARGET_RENDER_ACCESS_OPTIMAL;
652 transitionToRender.subresourceRange = srRange;
653 xglCmdPrepareImages( m_cmdBuffer, 1, &transitionToRender );
Courtney Goeltzenleuchter04814f82014-09-01 16:37:18 -0600654 renderTarget->state(( XGL_IMAGE_STATE ) transitionToClear.newState);
Courtney Goeltzenleuchtera948d842014-08-22 16:27:58 -0600655
656 // bind render target
657 XGL_COLOR_ATTACHMENT_BIND_INFO colorBind = {};
Courtney Goeltzenleuchter04814f82014-09-01 16:37:18 -0600658 colorBind.view = renderTarget->targetView();
Courtney Goeltzenleuchtera948d842014-08-22 16:27:58 -0600659 colorBind.colorAttachmentState = XGL_IMAGE_STATE_TARGET_RENDER_ACCESS_OPTIMAL;
660 xglCmdBindAttachments(m_cmdBuffer, 1, &colorBind, NULL );
661
662 // set all states
663 xglCmdBindStateObject( m_cmdBuffer, XGL_STATE_BIND_RASTER, m_stateRaster );
664 xglCmdBindStateObject( m_cmdBuffer, XGL_STATE_BIND_VIEWPORT, m_stateViewport );
Courtney Goeltzenleuchter68cfe612014-08-26 18:16:41 -0600665 xglCmdBindStateObject( m_cmdBuffer, XGL_STATE_BIND_COLOR_BLEND, m_colorBlend);
Courtney Goeltzenleuchtera948d842014-08-22 16:27:58 -0600666 xglCmdBindStateObject( m_cmdBuffer, XGL_STATE_BIND_DEPTH_STENCIL, m_stateDepthStencil );
667 xglCmdBindStateObject( m_cmdBuffer, XGL_STATE_BIND_MSAA, m_stateMsaa );
668
669 // bind pipeline, vertex buffer (descriptor set) and WVP (dynamic memory view)
670 xglCmdBindPipeline( m_cmdBuffer, XGL_PIPELINE_BIND_POINT_GRAPHICS, pipeline );
671// xglCmdBindDescriptorSet(m_cmdBuffer, XGL_PIPELINE_BIND_POINT_GRAPHICS, 0, m_rsrcDescSet, 0 );
672// xglCmdBindDynamicMemoryView( m_cmdBuffer, XGL_PIPELINE_BIND_POINT_GRAPHICS, &m_constantBufferView );
673
Chia-I Wuf070ec12014-08-30 23:58:36 +0800674 xglCmdResetQueryPool(m_cmdBuffer, query, 0, 1);
675 xglCmdBeginQuery(m_cmdBuffer, query, 0, 0);
676
Courtney Goeltzenleuchtera948d842014-08-22 16:27:58 -0600677 // render the cube
678 xglCmdDraw( m_cmdBuffer, 0, 3, 0, 1 );
679
Chia-I Wuf070ec12014-08-30 23:58:36 +0800680 xglCmdEndQuery(m_cmdBuffer, query, 0);
681
Courtney Goeltzenleuchtera948d842014-08-22 16:27:58 -0600682 // prepare the back buffer for present
683// XGL_IMAGE_STATE_TRANSITION transitionToPresent = {};
684// transitionToPresent.image = m_image;
685// transitionToPresent.oldState = m_image_state;
686// transitionToPresent.newState = m_display.fullscreen ? XGL_WSI_WIN_PRESENT_SOURCE_FLIP : XGL_WSI_WIN_PRESENT_SOURCE_BLT;
687// transitionToPresent.subresourceRange = srRange;
688// xglCmdPrepareImages( m_cmdBuffer, 1, &transitionToPresent );
689// m_image_state = ( XGL_IMAGE_STATE ) transitionToPresent.newState;
690
691 // finalize recording of the command buffer
692 err = xglEndCommandBuffer( m_cmdBuffer );
693 ASSERT_XGL_SUCCESS( err );
694
695 // this command buffer only uses the vertex buffer memory
696 m_numMemRefs = 0;
697// m_memRefs[0].flags = 0;
698// m_memRefs[0].mem = m_vtxBufferMemory;
699
700 // submit the command buffer to the universal queue
701 err = xglQueueSubmit( m_device->m_queue, 1, &m_cmdBuffer, m_numMemRefs, m_memRefs, NULL );
702 ASSERT_XGL_SUCCESS( err );
703
Chia-I Wuf34ac502014-08-27 14:58:05 +0800704 err = xglQueueWaitIdle( m_device->m_queue );
705 ASSERT_XGL_SUCCESS( err );
706
Courtney Goeltzenleuchter68cfe612014-08-26 18:16:41 -0600707 // Wait for work to finish before cleaning up.
708 xglDeviceWaitIdle(m_device->device());
709
Chia-I Wuf070ec12014-08-30 23:58:36 +0800710 XGL_PIPELINE_STATISTICS_DATA stats;
711 XGL_SIZE stats_size;
712 err = xglGetQueryPoolResults(query, 0, 1, &stats_size, &stats);
713 ASSERT_XGL_SUCCESS( err );
714 ASSERT_EQ(stats_size, sizeof(stats));
715
716 ASSERT_EQ(stats.vsInvocations, 3);
717 ASSERT_EQ(stats.cPrimitives, 1);
718 ASSERT_EQ(stats.cInvocations, 1);
719
720 DestroyQueryPool(query, query_mem);
721
Courtney Goeltzenleuchter04814f82014-09-01 16:37:18 -0600722 const ::testing::TestInfo* const test_info =
723 ::testing::UnitTest::GetInstance()->current_test_info();
724
Courtney Goeltzenleuchter28029792014-09-04 16:26:02 -0600725// renderTarget->WritePPM(test_info->test_case_name());
Courtney Goeltzenleuchter04814f82014-09-01 16:37:18 -0600726// m_screen.Display(renderTarget, m_image_mem);
Courtney Goeltzenleuchter28029792014-09-04 16:26:02 -0600727 RecordImage(renderTarget);
Chia-I Wuf34ac502014-08-27 14:58:05 +0800728
Courtney Goeltzenleuchtera948d842014-08-22 16:27:58 -0600729 ASSERT_XGL_SUCCESS(xglDestroyObject(pipeline));
Courtney Goeltzenleuchter68cfe612014-08-26 18:16:41 -0600730 ASSERT_XGL_SUCCESS(xglDestroyObject(m_cmdBuffer));
731 ASSERT_XGL_SUCCESS(xglDestroyObject(m_stateRaster));
732 ASSERT_XGL_SUCCESS(xglDestroyObject(m_stateViewport));
733 ASSERT_XGL_SUCCESS(xglDestroyObject(m_stateDepthStencil));
734 ASSERT_XGL_SUCCESS(xglDestroyObject(m_stateMsaa));
Courtney Goeltzenleuchter04814f82014-09-01 16:37:18 -0600735 free(renderTarget);
Courtney Goeltzenleuchtera948d842014-08-22 16:27:58 -0600736}
737
Chia-I Wuf34ac502014-08-27 14:58:05 +0800738
Courtney Goeltzenleuchtera948d842014-08-22 16:27:58 -0600739TEST_F(XglRenderTest, TestDrawTriangle) {
740 DrawTriangleTest();
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600741}
742
743int main(int argc, char **argv) {
Courtney Goeltzenleuchter28029792014-09-04 16:26:02 -0600744 int result;
745
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600746 ::testing::InitGoogleTest(&argc, argv);
Courtney Goeltzenleuchter28029792014-09-04 16:26:02 -0600747 XglTestFramework::InitArgs(&argc, argv);
748
749 result = RUN_ALL_TESTS();
750
751 XglTestFramework::Finish();
752 return result;
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600753}