blob: 60b47d4effe5c6f203277935da9b5bd330aada12 [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);
Tobin Ehlis34e0e442014-10-07 14:41:29 -0600202 void CreateDefaultPipeline(XGL_PIPELINE* pipeline, XGL_SHADER* vs, XGL_SHADER* ps, int width, int height);
203 void GenerateClearAndPrepareBufferCmds(XglImage *renderTarget);
204 void GenerateBindRenderTargetCmd(XglImage *renderTarget);
205 void GenerateBindStateAndPipelineCmds(XGL_PIPELINE* pipeline);
Chia-I Wua3b9d6a2014-08-30 23:53:01 +0800206
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600207 XGL_DEVICE device() {return m_device->device();}
Chia-I Wu6e9789c2014-08-30 14:03:32 +0800208 void CreateShader(XGL_PIPELINE_SHADER_STAGE stage, XGL_SHADER *pshader);
Courtney Goeltzenleuchterac8bd172014-08-20 15:28:00 -0600209 void InitPipeline();
Courtney Goeltzenleuchtera948d842014-08-22 16:27:58 -0600210 void InitMesh( XGL_UINT32 numVertices, XGL_GPU_SIZE vbStride, const void* vertices );
211 void DrawTriangleTest();
Tobin Ehlis34e0e442014-10-07 14:41:29 -0600212 void DrawRotatedTriangleTest();
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600213
214protected:
215 XGL_APPLICATION_INFO app_info;
216 XGL_PHYSICAL_GPU objs[MAX_GPUS];
217 XGL_UINT gpu_count;
Courtney Goeltzenleuchtera948d842014-08-22 16:27:58 -0600218 XGL_GPU_MEMORY m_descriptor_set_mem;
219 XGL_GPU_MEMORY m_pipe_mem;
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600220 XglDevice *m_device;
Courtney Goeltzenleuchterac8bd172014-08-20 15:28:00 -0600221 XGL_CMD_BUFFER m_cmdBuffer;
Courtney Goeltzenleuchtera948d842014-08-22 16:27:58 -0600222 XGL_UINT32 m_numVertices;
223 XGL_MEMORY_VIEW_ATTACH_INFO m_vtxBufferView;
224 XGL_GPU_MEMORY m_vtxBufferMem;
225 XGL_UINT32 m_numMemRefs;
226 XGL_MEMORY_REF m_memRefs[5];
227 XGL_RASTER_STATE_OBJECT m_stateRaster;
Courtney Goeltzenleuchter68cfe612014-08-26 18:16:41 -0600228 XGL_COLOR_BLEND_STATE_OBJECT m_colorBlend;
Courtney Goeltzenleuchtera948d842014-08-22 16:27:58 -0600229 XGL_VIEWPORT_STATE_OBJECT m_stateViewport;
230 XGL_DEPTH_STENCIL_STATE_OBJECT m_stateDepthStencil;
231 XGL_MSAA_STATE_OBJECT m_stateMsaa;
232 XGL_DESCRIPTOR_SET m_rsrcDescSet;
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600233
234 virtual void SetUp() {
235 XGL_RESULT err;
236
237 this->app_info.sType = XGL_STRUCTURE_TYPE_APPLICATION_INFO;
238 this->app_info.pNext = NULL;
239 this->app_info.pAppName = (const XGL_CHAR *) "base";
240 this->app_info.appVersion = 1;
241 this->app_info.pEngineName = (const XGL_CHAR *) "unittest";
242 this->app_info.engineVersion = 1;
243 this->app_info.apiVersion = XGL_MAKE_VERSION(0, 22, 0);
244
Courtney Goeltzenleuchtera948d842014-08-22 16:27:58 -0600245 memset(&m_vtxBufferView, 0, sizeof(m_vtxBufferView));
246 m_vtxBufferView.sType = XGL_STRUCTURE_TYPE_MEMORY_VIEW_ATTACH_INFO;
247
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600248 err = xglInitAndEnumerateGpus(&app_info, NULL,
249 MAX_GPUS, &this->gpu_count, objs);
250 ASSERT_XGL_SUCCESS(err);
251 ASSERT_GE(1, this->gpu_count) << "No GPU available";
252
253 m_device = new XglDevice(0, objs[0]);
254 m_device->get_device_queue();
255 }
256
257 virtual void TearDown() {
258 xglInitAndEnumerateGpus(&this->app_info, XGL_NULL_HANDLE, 0, &gpu_count, XGL_NULL_HANDLE);
Tobin Ehlisa9b13542014-10-23 13:45:13 -0600259 m_device->destroy_device();
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600260 }
261};
262
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600263
Chia-I Wua3b9d6a2014-08-30 23:53:01 +0800264void XglRenderTest::CreateQueryPool(XGL_QUERY_TYPE type, XGL_UINT slots,
265 XGL_QUERY_POOL *pPool, XGL_GPU_MEMORY *pMem)
266{
267 XGL_RESULT err;
268
269 XGL_QUERY_POOL_CREATE_INFO poolCreateInfo = {};
270 poolCreateInfo.sType = XGL_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
271 poolCreateInfo.pNext = NULL;
272 poolCreateInfo.queryType = type;
273 poolCreateInfo.slots = slots;
274
275 err = xglCreateQueryPool(device(), &poolCreateInfo, pPool);
276 ASSERT_XGL_SUCCESS(err);
277
278 XGL_MEMORY_REQUIREMENTS mem_req;
Jon Ashburnb8e43892014-09-25 14:36:58 -0600279 XGL_UINT data_size = sizeof(mem_req);
Chia-I Wua3b9d6a2014-08-30 23:53:01 +0800280 err = xglGetObjectInfo(*pPool, XGL_INFO_TYPE_MEMORY_REQUIREMENTS,
281 &data_size, &mem_req);
282 ASSERT_XGL_SUCCESS(err);
283 ASSERT_EQ(data_size, sizeof(mem_req));
284
285 if (!mem_req.size) {
286 *pMem = XGL_NULL_HANDLE;
287 return;
288 }
289
290 XGL_MEMORY_ALLOC_INFO mem_info;
291
292 memset(&mem_info, 0, sizeof(mem_info));
293 mem_info.sType = XGL_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
294 mem_info.allocationSize = mem_req.size;
295 mem_info.alignment = mem_req.alignment;
296 mem_info.heapCount = mem_req.heapCount;
297 memcpy(mem_info.heaps, mem_req.heaps, sizeof(XGL_UINT)*XGL_MAX_MEMORY_HEAPS);
298 mem_info.memPriority = XGL_MEMORY_PRIORITY_NORMAL;
299 mem_info.flags = XGL_MEMORY_ALLOC_SHAREABLE_BIT;
300 err = xglAllocMemory(device(), &mem_info, pMem);
301 ASSERT_XGL_SUCCESS(err);
302
303 err = xglBindObjectMemory(*pPool, *pMem, 0);
304 ASSERT_XGL_SUCCESS(err);
305}
306
307void XglRenderTest::DestroyQueryPool(XGL_QUERY_POOL pool, XGL_GPU_MEMORY mem)
308{
309 ASSERT_XGL_SUCCESS(xglBindObjectMemory(pool, XGL_NULL_HANDLE, 0));
310 ASSERT_XGL_SUCCESS(xglFreeMemory(mem));
311 ASSERT_XGL_SUCCESS(xglDestroyObject(pool));
312}
313
Chia-I Wu6e9789c2014-08-30 14:03:32 +0800314void XglRenderTest::CreateShader(XGL_PIPELINE_SHADER_STAGE stage, XGL_SHADER *pshader)
Courtney Goeltzenleuchterac8bd172014-08-20 15:28:00 -0600315{
Chia-I Wu4b7b4582014-08-28 12:27:21 +0800316 struct icd_bil_header *pBIL;
Courtney Goeltzenleuchter76a643b2014-08-21 17:34:22 -0600317 char * memblock;
Chia-I Wu6e9789c2014-08-30 14:03:32 +0800318 const char *kernel;
319 size_t kernel_size;
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600320 XGL_RESULT err;
321
Chia-I Wu6e9789c2014-08-30 14:03:32 +0800322 const XGL_PHYSICAL_GPU_PROPERTIES *props = &m_device->props;
323 const int gen = (strstr((const char *) props->gpuName, "Sandybridge")) ? 6 : 7;
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600324
Chia-I Wu6e9789c2014-08-30 14:03:32 +0800325 if (stage == XGL_SHADER_STAGE_VERTEX) {
326 if (gen == 6) {
327 kernel = (const char *) gen6_vs;
328 kernel_size = sizeof(gen6_vs);
329 } else {
330 kernel = (const char *) gen7_vs;
331 kernel_size = sizeof(gen7_vs);
332 }
333 } else {
334 if (gen == 6) {
335 kernel = (const char *) gen6_fs;
336 kernel_size = sizeof(gen6_fs);
337 } else {
338 kernel = (const char *) gen7_fs;
339 kernel_size = sizeof(gen7_fs);
340 }
341 }
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600342
Chia-I Wu6e9789c2014-08-30 14:03:32 +0800343 memblock = new char [sizeof(*pBIL) + kernel_size];
Courtney Goeltzenleuchtera948d842014-08-22 16:27:58 -0600344 ASSERT_TRUE(memblock != NULL) << "memory allocation failed";
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600345
Chia-I Wu4b7b4582014-08-28 12:27:21 +0800346 pBIL = (struct icd_bil_header *) memblock;
347 pBIL->magic = ICD_BIL_MAGIC;
348 pBIL->version = ICD_BIL_VERSION;
349
Chia-I Wu6e9789c2014-08-30 14:03:32 +0800350 pBIL->gen_magic = (stage == XGL_SHADER_STAGE_VERTEX) ? 'v' : 'w';
351 memcpy(pBIL + 1, kernel, kernel_size);
Chia-I Wu4b7b4582014-08-28 12:27:21 +0800352
Courtney Goeltzenleuchtera948d842014-08-22 16:27:58 -0600353 XGL_SHADER_CREATE_INFO createInfo;
354 XGL_SHADER shader;
Courtney Goeltzenleuchter76a643b2014-08-21 17:34:22 -0600355
Courtney Goeltzenleuchtera948d842014-08-22 16:27:58 -0600356 createInfo.sType = XGL_STRUCTURE_TYPE_SHADER_CREATE_INFO;
357 createInfo.pNext = NULL;
358 createInfo.pCode = memblock;
Chia-I Wu6e9789c2014-08-30 14:03:32 +0800359 createInfo.codeSize = sizeof(*pBIL) + kernel_size;
Courtney Goeltzenleuchtera948d842014-08-22 16:27:58 -0600360 createInfo.flags = 0;
361 err = xglCreateShader(device(), &createInfo, &shader);
362 ASSERT_XGL_SUCCESS(err);
Courtney Goeltzenleuchter76a643b2014-08-21 17:34:22 -0600363
Courtney Goeltzenleuchtera948d842014-08-22 16:27:58 -0600364 delete[] memblock;
Courtney Goeltzenleuchter76a643b2014-08-21 17:34:22 -0600365
Courtney Goeltzenleuchtera948d842014-08-22 16:27:58 -0600366 *pshader = shader;
Courtney Goeltzenleuchterac8bd172014-08-20 15:28:00 -0600367}
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600368
Courtney Goeltzenleuchtera948d842014-08-22 16:27:58 -0600369// this function will create the vertex buffer and fill it with the mesh data
370void XglRenderTest::InitMesh( XGL_UINT32 numVertices, XGL_GPU_SIZE vbStride,
371 const void* vertices )
372{
373 XGL_RESULT err = XGL_SUCCESS;
374
375 assert( numVertices * vbStride > 0 );
376 m_numVertices = numVertices;
377
378 XGL_MEMORY_ALLOC_INFO alloc_info = {};
379 XGL_UINT8 *pData;
380
381 alloc_info.sType = XGL_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
382 alloc_info.allocationSize = numVertices * vbStride;
383 alloc_info.alignment = 0;
384 alloc_info.heapCount = 1;
385 alloc_info.heaps[0] = 0; // TODO: Use known existing heap
386
387 alloc_info.flags = XGL_MEMORY_HEAP_CPU_VISIBLE_BIT;
388 alloc_info.memPriority = XGL_MEMORY_PRIORITY_NORMAL;
389
390 err = xglAllocMemory(device(), &alloc_info, &m_vtxBufferMem);
391 ASSERT_XGL_SUCCESS(err);
392
393 err = xglMapMemory(m_vtxBufferMem, 0, (XGL_VOID **) &pData);
394 ASSERT_XGL_SUCCESS(err);
395
396 memcpy(pData, vertices, alloc_info.allocationSize);
397
398 err = xglUnmapMemory(m_vtxBufferMem);
399 ASSERT_XGL_SUCCESS(err);
400
401 // set up the memory view for the vertex buffer
402 this->m_vtxBufferView.stride = vbStride;
403 this->m_vtxBufferView.range = numVertices * vbStride;
404 this->m_vtxBufferView.offset = 0;
405 this->m_vtxBufferView.mem = m_vtxBufferMem;
406 this->m_vtxBufferView.format.channelFormat = XGL_CH_FMT_UNDEFINED;
407 this->m_vtxBufferView.format.numericFormat = XGL_NUM_FMT_UNDEFINED;
408
409 // open the command buffer
410 err = xglBeginCommandBuffer( m_cmdBuffer, 0 );
411 ASSERT_XGL_SUCCESS(err);
412
413 XGL_MEMORY_STATE_TRANSITION transition = {};
414 transition.mem = m_vtxBufferMem;
415 transition.oldState = XGL_MEMORY_STATE_DATA_TRANSFER;
416 transition.newState = XGL_MEMORY_STATE_GRAPHICS_SHADER_READ_ONLY;
417 transition.offset = 0;
418 transition.regionSize = numVertices * vbStride;
419
420 // write transition to the command buffer
421 xglCmdPrepareMemoryRegions( m_cmdBuffer, 1, &transition );
422 this->m_vtxBufferView.state = XGL_MEMORY_STATE_GRAPHICS_SHADER_READ_ONLY;
423
424 // finish recording the command buffer
425 err = xglEndCommandBuffer( m_cmdBuffer );
426 ASSERT_XGL_SUCCESS(err);
427
428 // this command buffer only uses the vertex buffer memory
429 m_numMemRefs = 1;
430 m_memRefs[0].flags = 0;
431 m_memRefs[0].mem = m_vtxBufferMem;
432
433 // submit the command buffer to the universal queue
434 err = xglQueueSubmit( m_device->m_queue, 1, &m_cmdBuffer, m_numMemRefs, m_memRefs, NULL );
435 ASSERT_XGL_SUCCESS(err);
436}
437
Tobin Ehlis34e0e442014-10-07 14:41:29 -0600438void XglRenderTest::CreateDefaultPipeline(XGL_PIPELINE* pipeline, XGL_SHADER* vs, XGL_SHADER* ps, int width, int height)
Courtney Goeltzenleuchtera948d842014-08-22 16:27:58 -0600439{
Courtney Goeltzenleuchterac8bd172014-08-20 15:28:00 -0600440 XGL_RESULT err;
441 XGL_GRAPHICS_PIPELINE_CREATE_INFO info = {};
Courtney Goeltzenleuchterac8bd172014-08-20 15:28:00 -0600442 XGL_PIPELINE_SHADER_STAGE_CREATE_INFO vs_stage;
443 XGL_PIPELINE_SHADER_STAGE_CREATE_INFO ps_stage;
Tobin Ehlis34e0e442014-10-07 14:41:29 -0600444 //XGL_PIPELINE pipeline;
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600445
Courtney Goeltzenleuchtera948d842014-08-22 16:27:58 -0600446 // create a raster state (solid, back-face culling)
447 XGL_RASTER_STATE_CREATE_INFO raster = {};
448 raster.sType = XGL_STRUCTURE_TYPE_RASTER_STATE_CREATE_INFO;
449 raster.fillMode = XGL_FILL_SOLID;
Chia-I Wu0059c372014-08-31 00:52:42 +0800450 raster.cullMode = XGL_CULL_NONE;
Courtney Goeltzenleuchtera948d842014-08-22 16:27:58 -0600451 raster.frontFace = XGL_FRONT_FACE_CCW;
452 err = xglCreateRasterState( device(), &raster, &m_stateRaster );
453 ASSERT_XGL_SUCCESS(err);
454
455 XGL_VIEWPORT_STATE_CREATE_INFO viewport = {};
456 viewport.viewportCount = 1;
457 viewport.scissorEnable = XGL_FALSE;
458 viewport.viewports[0].originX = 0;
459 viewport.viewports[0].originY = 0;
460 viewport.viewports[0].width = 1.f * width;
461 viewport.viewports[0].height = 1.f * height;
462 viewport.viewports[0].minDepth = 0.f;
463 viewport.viewports[0].maxDepth = 1.f;
464
465 err = xglCreateViewportState( device(), &viewport, &m_stateViewport );
466 ASSERT_XGL_SUCCESS( err );
467
Courtney Goeltzenleuchter68cfe612014-08-26 18:16:41 -0600468 XGL_COLOR_BLEND_STATE_CREATE_INFO blend = {};
469 blend.sType = XGL_STRUCTURE_TYPE_COLOR_BLEND_STATE_CREATE_INFO;
470 err = xglCreateColorBlendState(device(), &blend, &m_colorBlend);
471 ASSERT_XGL_SUCCESS( err );
472
Courtney Goeltzenleuchtera948d842014-08-22 16:27:58 -0600473 XGL_DEPTH_STENCIL_STATE_CREATE_INFO depthStencil = {};
474 depthStencil.sType = XGL_STRUCTURE_TYPE_DEPTH_STENCIL_STATE_CREATE_INFO;
475 depthStencil.depthTestEnable = XGL_FALSE;
476 depthStencil.depthWriteEnable = XGL_FALSE;
477 depthStencil.depthFunc = XGL_COMPARE_LESS_EQUAL;
478 depthStencil.depthBoundsEnable = XGL_FALSE;
479 depthStencil.minDepth = 0.f;
480 depthStencil.maxDepth = 1.f;
481 depthStencil.back.stencilDepthFailOp = XGL_STENCIL_OP_KEEP;
482 depthStencil.back.stencilFailOp = XGL_STENCIL_OP_KEEP;
483 depthStencil.back.stencilPassOp = XGL_STENCIL_OP_KEEP;
484 depthStencil.back.stencilRef = 0x00;
485 depthStencil.back.stencilFunc = XGL_COMPARE_ALWAYS;
486 depthStencil.front = depthStencil.back;
487
488 err = xglCreateDepthStencilState( device(), &depthStencil, &m_stateDepthStencil );
489 ASSERT_XGL_SUCCESS( err );
490
491 XGL_MSAA_STATE_CREATE_INFO msaa = {};
492 msaa.sType = XGL_STRUCTURE_TYPE_MSAA_STATE_CREATE_INFO;
493 msaa.sampleMask = 1;
494 msaa.samples = 1;
495
496 err = xglCreateMsaaState( device(), &msaa, &m_stateMsaa );
497 ASSERT_XGL_SUCCESS( err );
498
499 XGL_CMD_BUFFER_CREATE_INFO cmdInfo = {};
500
501 cmdInfo.sType = XGL_STRUCTURE_TYPE_CMD_BUFFER_CREATE_INFO;
502 cmdInfo.queueType = XGL_QUEUE_TYPE_GRAPHICS;
503 err = xglCreateCommandBuffer(device(), &cmdInfo, &m_cmdBuffer);
504 ASSERT_XGL_SUCCESS(err) << "xglCreateCommandBuffer failed";
505
Courtney Goeltzenleuchtera948d842014-08-22 16:27:58 -0600506#if 0
507 // Create descriptor set for our one resource
508 XGL_DESCRIPTOR_SET_CREATE_INFO descriptorInfo = {};
509 descriptorInfo.sType = XGL_STRUCTURE_TYPE_DESCRIPTOR_SET_CREATE_INFO;
510 descriptorInfo.slots = 1; // Vertex buffer only
511
512 // create a descriptor set with a single slot
513 err = xglCreateDescriptorSet( device(), &descriptorInfo, &m_rsrcDescSet );
514 ASSERT_XGL_SUCCESS(err) << "xglCreateDescriptorSet failed";
515
516 // bind memory to the descriptor set
517 err = m_device->AllocAndBindGpuMemory(m_rsrcDescSet, "DescriptorSet", &m_descriptor_set_mem);
518
519 // set up the memory view for the vertex buffer
520 this->m_vtxBufferView.stride = vbStride;
521 this->m_vtxBufferView.range = numVertices * vbStride;
522 this->m_vtxBufferView.offset = 0;
523 this->m_vtxBufferView.mem = m_vtxBufferMem;
524 this->m_vtxBufferView.format.channelFormat = XGL_CH_FMT_UNDEFINED;
525 this->m_vtxBufferView.format.numericFormat = XGL_NUM_FMT_UNDEFINED;
526 // write the vertex buffer view to the descriptor set
527 xglBeginDescriptorSetUpdate( m_rsrcDescSet );
528 xglAttachMemoryViewDescriptors( m_rsrcDescSet, 0, 1, &m_vtxBufferView );
529 xglEndDescriptorSetUpdate( m_rsrcDescSet );
530#endif
Courtney Goeltzenleuchterac8bd172014-08-20 15:28:00 -0600531
Tobin Ehlis34e0e442014-10-07 14:41:29 -0600532 ASSERT_NO_FATAL_FAILURE(CreateShader(XGL_SHADER_STAGE_VERTEX, vs));
Courtney Goeltzenleuchterac8bd172014-08-20 15:28:00 -0600533
534 vs_stage.sType = XGL_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
535 vs_stage.pNext = XGL_NULL_HANDLE;
536 vs_stage.shader.stage = XGL_SHADER_STAGE_VERTEX;
Tobin Ehlis34e0e442014-10-07 14:41:29 -0600537 vs_stage.shader.shader = *vs;
Jon Ashburnf93c1bd2014-10-20 13:37:31 -0600538 for (unsigned int i = 0; i < XGL_MAX_DESCRIPTOR_SETS; i++)
539 vs_stage.shader.descriptorSetMapping[i].descriptorCount = 0;
Courtney Goeltzenleuchterac8bd172014-08-20 15:28:00 -0600540 vs_stage.shader.linkConstBufferCount = 0;
541 vs_stage.shader.pLinkConstBufferInfo = XGL_NULL_HANDLE;
Chia-I Wu3c89e4e2014-08-23 17:47:45 +0800542 vs_stage.shader.dynamicMemoryViewMapping.slotObjectType = XGL_SLOT_UNUSED;
Courtney Goeltzenleuchterac8bd172014-08-20 15:28:00 -0600543 vs_stage.shader.dynamicMemoryViewMapping.shaderEntityIndex = 0;
544
Tobin Ehlis34e0e442014-10-07 14:41:29 -0600545 ASSERT_NO_FATAL_FAILURE(CreateShader(XGL_SHADER_STAGE_FRAGMENT, ps));
Courtney Goeltzenleuchterac8bd172014-08-20 15:28:00 -0600546
547 ps_stage.sType = XGL_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
548 ps_stage.pNext = &vs_stage;
549 ps_stage.shader.stage = XGL_SHADER_STAGE_FRAGMENT;
Tobin Ehlis34e0e442014-10-07 14:41:29 -0600550 ps_stage.shader.shader = *ps;
Courtney Goeltzenleuchterac8bd172014-08-20 15:28:00 -0600551 // TODO: Do we need a descriptor set mapping for fragment?
Jon Ashburnf93c1bd2014-10-20 13:37:31 -0600552 for (unsigned int i = 0; i < XGL_MAX_DESCRIPTOR_SETS; i++)
553 ps_stage.shader.descriptorSetMapping[i].descriptorCount = 0;
Courtney Goeltzenleuchterac8bd172014-08-20 15:28:00 -0600554 ps_stage.shader.linkConstBufferCount = 0;
555 ps_stage.shader.pLinkConstBufferInfo = XGL_NULL_HANDLE;
Chia-I Wu3c89e4e2014-08-23 17:47:45 +0800556 ps_stage.shader.dynamicMemoryViewMapping.slotObjectType = XGL_SLOT_UNUSED;
Courtney Goeltzenleuchterac8bd172014-08-20 15:28:00 -0600557 ps_stage.shader.dynamicMemoryViewMapping.shaderEntityIndex = 0;
558
559 XGL_PIPELINE_IA_STATE_CREATE_INFO ia_state = {
560 XGL_STRUCTURE_TYPE_PIPELINE_IA_STATE_CREATE_INFO, // sType
561 &ps_stage, // pNext
562 XGL_TOPOLOGY_TRIANGLE_LIST, // XGL_PRIMITIVE_TOPOLOGY
563 XGL_FALSE, // disableVertexReuse
564 XGL_PROVOKING_VERTEX_LAST, // XGL_PROVOKING_VERTEX_CONVENTION
565 XGL_FALSE, // primitiveRestartEnable
566 0 // primitiveRestartIndex
567 };
568
569 XGL_PIPELINE_RS_STATE_CREATE_INFO rs_state = {
570 XGL_STRUCTURE_TYPE_PIPELINE_RS_STATE_CREATE_INFO,
571 &ia_state,
572 XGL_FALSE, // depthClipEnable
573 XGL_FALSE, // rasterizerDiscardEnable
574 1.0 // pointSize
575 };
576
577 XGL_PIPELINE_CB_STATE cb_state = {
578 XGL_STRUCTURE_TYPE_PIPELINE_CB_STATE_CREATE_INFO,
579 &rs_state,
580 XGL_FALSE, // alphaToCoverageEnable
581 XGL_FALSE, // dualSourceBlendEnable
582 XGL_LOGIC_OP_COPY, // XGL_LOGIC_OP
583 { // XGL_PIPELINE_CB_ATTACHMENT_STATE
584 {
585 XGL_FALSE, // blendEnable
Chia-I Wuf5d5c1a2014-08-27 15:02:10 +0800586 {XGL_CH_FMT_R8G8B8A8, XGL_NUM_FMT_UNORM}, // XGL_FORMAT
Courtney Goeltzenleuchterac8bd172014-08-20 15:28:00 -0600587 0xF // channelWriteMask
588 }
589 }
590 };
591
592 // TODO: Should take depth buffer format from queried formats
593 XGL_PIPELINE_DB_STATE_CREATE_INFO db_state = {
594 XGL_STRUCTURE_TYPE_PIPELINE_DB_STATE_CREATE_INFO,
595 &cb_state,
596 {XGL_CH_FMT_R32, XGL_NUM_FMT_DS} // XGL_FORMAT
597 };
598
599 info.sType = XGL_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
600 info.pNext = &db_state;
601 info.flags = 0;
Tobin Ehlis34e0e442014-10-07 14:41:29 -0600602
603 err = xglCreateGraphicsPipeline(device(), &info, pipeline);
Courtney Goeltzenleuchterac8bd172014-08-20 15:28:00 -0600604 ASSERT_XGL_SUCCESS(err);
Tobin Ehlis34e0e442014-10-07 14:41:29 -0600605}
Courtney Goeltzenleuchterac8bd172014-08-20 15:28:00 -0600606
Tobin Ehlis34e0e442014-10-07 14:41:29 -0600607void XglRenderTest::GenerateClearAndPrepareBufferCmds(XglImage *renderTarget)
608{
Courtney Goeltzenleuchtera948d842014-08-22 16:27:58 -0600609 // whatever we want to do, we do it to the whole buffer
610 XGL_IMAGE_SUBRESOURCE_RANGE srRange = {};
611 srRange.aspect = XGL_IMAGE_ASPECT_COLOR;
612 srRange.baseMipLevel = 0;
613 srRange.mipLevels = XGL_LAST_MIP_OR_SLICE;
614 srRange.baseArraySlice = 0;
615 srRange.arraySize = XGL_LAST_MIP_OR_SLICE;
616
617 // prepare the whole back buffer for clear
618 XGL_IMAGE_STATE_TRANSITION transitionToClear = {};
Courtney Goeltzenleuchter04814f82014-09-01 16:37:18 -0600619 transitionToClear.image = renderTarget->image();
620 transitionToClear.oldState = renderTarget->state();
Courtney Goeltzenleuchtera948d842014-08-22 16:27:58 -0600621 transitionToClear.newState = XGL_IMAGE_STATE_CLEAR;
622 transitionToClear.subresourceRange = srRange;
623 xglCmdPrepareImages( m_cmdBuffer, 1, &transitionToClear );
Courtney Goeltzenleuchter04814f82014-09-01 16:37:18 -0600624 renderTarget->state(( XGL_IMAGE_STATE ) transitionToClear.newState);
Courtney Goeltzenleuchtera948d842014-08-22 16:27:58 -0600625
626 // clear the back buffer to dark grey
627 XGL_UINT clearColor[4] = {64, 64, 64, 0};
Courtney Goeltzenleuchter04814f82014-09-01 16:37:18 -0600628 xglCmdClearColorImageRaw( m_cmdBuffer, renderTarget->image(), clearColor, 1, &srRange );
Courtney Goeltzenleuchtera948d842014-08-22 16:27:58 -0600629
630 // prepare back buffer for rendering
631 XGL_IMAGE_STATE_TRANSITION transitionToRender = {};
Courtney Goeltzenleuchter04814f82014-09-01 16:37:18 -0600632 transitionToRender.image = renderTarget->image();
633 transitionToRender.oldState = renderTarget->state();
Courtney Goeltzenleuchtera948d842014-08-22 16:27:58 -0600634 transitionToRender.newState = XGL_IMAGE_STATE_TARGET_RENDER_ACCESS_OPTIMAL;
635 transitionToRender.subresourceRange = srRange;
636 xglCmdPrepareImages( m_cmdBuffer, 1, &transitionToRender );
Courtney Goeltzenleuchter04814f82014-09-01 16:37:18 -0600637 renderTarget->state(( XGL_IMAGE_STATE ) transitionToClear.newState);
Tobin Ehlis34e0e442014-10-07 14:41:29 -0600638}
Courtney Goeltzenleuchtera948d842014-08-22 16:27:58 -0600639
Tobin Ehlis34e0e442014-10-07 14:41:29 -0600640void XglRenderTest::GenerateBindRenderTargetCmd(XglImage *renderTarget)
641{
Courtney Goeltzenleuchtera948d842014-08-22 16:27:58 -0600642 // bind render target
643 XGL_COLOR_ATTACHMENT_BIND_INFO colorBind = {};
Courtney Goeltzenleuchter04814f82014-09-01 16:37:18 -0600644 colorBind.view = renderTarget->targetView();
Courtney Goeltzenleuchtera948d842014-08-22 16:27:58 -0600645 colorBind.colorAttachmentState = XGL_IMAGE_STATE_TARGET_RENDER_ACCESS_OPTIMAL;
646 xglCmdBindAttachments(m_cmdBuffer, 1, &colorBind, NULL );
Tobin Ehlis34e0e442014-10-07 14:41:29 -0600647}
Courtney Goeltzenleuchtera948d842014-08-22 16:27:58 -0600648
Tobin Ehlis34e0e442014-10-07 14:41:29 -0600649void XglRenderTest::GenerateBindStateAndPipelineCmds(XGL_PIPELINE* pipeline)
650{
Courtney Goeltzenleuchtera948d842014-08-22 16:27:58 -0600651 // set all states
652 xglCmdBindStateObject( m_cmdBuffer, XGL_STATE_BIND_RASTER, m_stateRaster );
653 xglCmdBindStateObject( m_cmdBuffer, XGL_STATE_BIND_VIEWPORT, m_stateViewport );
Courtney Goeltzenleuchter68cfe612014-08-26 18:16:41 -0600654 xglCmdBindStateObject( m_cmdBuffer, XGL_STATE_BIND_COLOR_BLEND, m_colorBlend);
Courtney Goeltzenleuchtera948d842014-08-22 16:27:58 -0600655 xglCmdBindStateObject( m_cmdBuffer, XGL_STATE_BIND_DEPTH_STENCIL, m_stateDepthStencil );
656 xglCmdBindStateObject( m_cmdBuffer, XGL_STATE_BIND_MSAA, m_stateMsaa );
657
658 // bind pipeline, vertex buffer (descriptor set) and WVP (dynamic memory view)
Tobin Ehlis34e0e442014-10-07 14:41:29 -0600659 xglCmdBindPipeline( m_cmdBuffer, XGL_PIPELINE_BIND_POINT_GRAPHICS, *pipeline );
660}
661
662void XglRenderTest::DrawRotatedTriangleTest()
663{
664 // TODO : This test will pass a matrix into VS to affect triangle orientation.
665}
666
667void XglRenderTest::DrawTriangleTest()
668{
669 XGL_PIPELINE pipeline;
670 XGL_SHADER vs, ps;
671 XGL_RESULT err;
672 int width = 256, height = 256;
673 CreateDefaultPipeline(&pipeline, &vs, &ps, width, height);
674 //ASSERT_XGL_SUCCESS(err);
675
676 err = m_device->AllocAndBindGpuMemory(pipeline, "Pipeline", &m_pipe_mem);
677 ASSERT_XGL_SUCCESS(err);
678
679 /*
680 * Shaders are now part of the pipeline, don't need these anymore
681 */
682 ASSERT_XGL_SUCCESS(xglDestroyObject(ps));
683 ASSERT_XGL_SUCCESS(xglDestroyObject(vs));
684
685 XGL_QUERY_POOL query;
686 XGL_GPU_MEMORY query_mem;
687 ASSERT_NO_FATAL_FAILURE(CreateQueryPool(XGL_QUERY_PIPELINE_STATISTICS, 1, &query, &query_mem));
688
689 XglImage *renderTarget;
690 XGL_FORMAT fmt = {
691 XGL_CH_FMT_R8G8B8A8,
692 XGL_NUM_FMT_UNORM
693 };
694 ASSERT_NO_FATAL_FAILURE(m_device->CreateImage(width, height, fmt,
695 XGL_IMAGE_USAGE_SHADER_ACCESS_WRITE_BIT |
696 XGL_IMAGE_USAGE_COLOR_ATTACHMENT_BIT,
697 &renderTarget));
698
699 // Build command buffer
700 err = xglBeginCommandBuffer(m_cmdBuffer, 0);
701 ASSERT_XGL_SUCCESS(err);
702
703 GenerateClearAndPrepareBufferCmds(renderTarget);
704 GenerateBindRenderTargetCmd(renderTarget);
705 GenerateBindStateAndPipelineCmds(&pipeline);
706
Courtney Goeltzenleuchtera948d842014-08-22 16:27:58 -0600707// xglCmdBindDescriptorSet(m_cmdBuffer, XGL_PIPELINE_BIND_POINT_GRAPHICS, 0, m_rsrcDescSet, 0 );
708// xglCmdBindDynamicMemoryView( m_cmdBuffer, XGL_PIPELINE_BIND_POINT_GRAPHICS, &m_constantBufferView );
709
Chia-I Wuf070ec12014-08-30 23:58:36 +0800710 xglCmdResetQueryPool(m_cmdBuffer, query, 0, 1);
711 xglCmdBeginQuery(m_cmdBuffer, query, 0, 0);
712
Courtney Goeltzenleuchtera948d842014-08-22 16:27:58 -0600713 // render the cube
714 xglCmdDraw( m_cmdBuffer, 0, 3, 0, 1 );
715
Chia-I Wuf070ec12014-08-30 23:58:36 +0800716 xglCmdEndQuery(m_cmdBuffer, query, 0);
717
Courtney Goeltzenleuchtera948d842014-08-22 16:27:58 -0600718 // prepare the back buffer for present
719// XGL_IMAGE_STATE_TRANSITION transitionToPresent = {};
720// transitionToPresent.image = m_image;
721// transitionToPresent.oldState = m_image_state;
722// transitionToPresent.newState = m_display.fullscreen ? XGL_WSI_WIN_PRESENT_SOURCE_FLIP : XGL_WSI_WIN_PRESENT_SOURCE_BLT;
723// transitionToPresent.subresourceRange = srRange;
724// xglCmdPrepareImages( m_cmdBuffer, 1, &transitionToPresent );
725// m_image_state = ( XGL_IMAGE_STATE ) transitionToPresent.newState;
726
727 // finalize recording of the command buffer
728 err = xglEndCommandBuffer( m_cmdBuffer );
729 ASSERT_XGL_SUCCESS( err );
730
731 // this command buffer only uses the vertex buffer memory
732 m_numMemRefs = 0;
733// m_memRefs[0].flags = 0;
734// m_memRefs[0].mem = m_vtxBufferMemory;
735
736 // submit the command buffer to the universal queue
737 err = xglQueueSubmit( m_device->m_queue, 1, &m_cmdBuffer, m_numMemRefs, m_memRefs, NULL );
738 ASSERT_XGL_SUCCESS( err );
739
Chia-I Wuf34ac502014-08-27 14:58:05 +0800740 err = xglQueueWaitIdle( m_device->m_queue );
741 ASSERT_XGL_SUCCESS( err );
742
Courtney Goeltzenleuchter68cfe612014-08-26 18:16:41 -0600743 // Wait for work to finish before cleaning up.
744 xglDeviceWaitIdle(m_device->device());
745
Chia-I Wuf070ec12014-08-30 23:58:36 +0800746 XGL_PIPELINE_STATISTICS_DATA stats;
Jon Ashburnb8e43892014-09-25 14:36:58 -0600747 XGL_SIZE stats_size = sizeof(stats);
Chia-I Wuf070ec12014-08-30 23:58:36 +0800748 err = xglGetQueryPoolResults(query, 0, 1, &stats_size, &stats);
749 ASSERT_XGL_SUCCESS( err );
750 ASSERT_EQ(stats_size, sizeof(stats));
751
752 ASSERT_EQ(stats.vsInvocations, 3);
753 ASSERT_EQ(stats.cPrimitives, 1);
754 ASSERT_EQ(stats.cInvocations, 1);
755
756 DestroyQueryPool(query, query_mem);
757
Courtney Goeltzenleuchter04814f82014-09-01 16:37:18 -0600758 const ::testing::TestInfo* const test_info =
759 ::testing::UnitTest::GetInstance()->current_test_info();
760
Courtney Goeltzenleuchter28029792014-09-04 16:26:02 -0600761// renderTarget->WritePPM(test_info->test_case_name());
Courtney Goeltzenleuchter04814f82014-09-01 16:37:18 -0600762// m_screen.Display(renderTarget, m_image_mem);
Courtney Goeltzenleuchter28029792014-09-04 16:26:02 -0600763 RecordImage(renderTarget);
Chia-I Wuf34ac502014-08-27 14:58:05 +0800764
Courtney Goeltzenleuchtera948d842014-08-22 16:27:58 -0600765 ASSERT_XGL_SUCCESS(xglDestroyObject(pipeline));
Courtney Goeltzenleuchter68cfe612014-08-26 18:16:41 -0600766 ASSERT_XGL_SUCCESS(xglDestroyObject(m_cmdBuffer));
767 ASSERT_XGL_SUCCESS(xglDestroyObject(m_stateRaster));
768 ASSERT_XGL_SUCCESS(xglDestroyObject(m_stateViewport));
769 ASSERT_XGL_SUCCESS(xglDestroyObject(m_stateDepthStencil));
770 ASSERT_XGL_SUCCESS(xglDestroyObject(m_stateMsaa));
Courtney Goeltzenleuchter04814f82014-09-01 16:37:18 -0600771 free(renderTarget);
Courtney Goeltzenleuchtera948d842014-08-22 16:27:58 -0600772}
773
Chia-I Wuf34ac502014-08-27 14:58:05 +0800774
Courtney Goeltzenleuchtera948d842014-08-22 16:27:58 -0600775TEST_F(XglRenderTest, TestDrawTriangle) {
776 DrawTriangleTest();
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600777}
778
Tobin Ehlis34e0e442014-10-07 14:41:29 -0600779TEST_F(XglRenderTest, TestDrawRotatedTriangle) {
780 DrawRotatedTriangleTest();
781}
782
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600783int main(int argc, char **argv) {
Courtney Goeltzenleuchter28029792014-09-04 16:26:02 -0600784 int result;
785
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600786 ::testing::InitGoogleTest(&argc, argv);
Courtney Goeltzenleuchter28029792014-09-04 16:26:02 -0600787 XglTestFramework::InitArgs(&argc, argv);
788
789 result = RUN_ALL_TESTS();
790
791 XglTestFramework::Finish();
792 return result;
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600793}