Courtney Goeltzenleuchter | cc5eb3a | 2014-08-19 18:35:50 -0600 | [diff] [blame] | 1 | // 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 Goeltzenleuchter | da91b95 | 2014-08-21 17:34:22 -0600 | [diff] [blame] | 60 | #include <iostream> |
| 61 | #include <fstream> |
| 62 | using namespace std; |
Courtney Goeltzenleuchter | cc5eb3a | 2014-08-19 18:35:50 -0600 | [diff] [blame] | 63 | |
| 64 | #include <xgl.h> |
| 65 | #include "gtest-1.7.0/include/gtest/gtest.h" |
| 66 | |
| 67 | #include "xgldevice.h" |
Chia-I Wu | fe7c1de | 2014-08-28 11:56:29 +0800 | [diff] [blame] | 68 | #include "icd-bil.h" |
Courtney Goeltzenleuchter | cc5eb3a | 2014-08-19 18:35:50 -0600 | [diff] [blame] | 69 | |
Courtney Goeltzenleuchter | f21d32d | 2014-09-01 13:57:15 -0600 | [diff] [blame] | 70 | #include "displayengine.h" |
| 71 | |
Courtney Goeltzenleuchter | 0246188 | 2014-08-22 16:27:58 -0600 | [diff] [blame] | 72 | //-------------------------------------------------------------------------------------- |
| 73 | // Mesh and VertexFormat Data |
| 74 | //-------------------------------------------------------------------------------------- |
| 75 | struct Vertex |
| 76 | { |
| 77 | XGL_FLOAT posX, posY, posZ, posW; // Position data |
| 78 | XGL_FLOAT r, g, b, a; // Color |
| 79 | }; |
| 80 | |
| 81 | #define XYZ1(_x_, _y_, _z_) (_x_), (_y_), (_z_), 1.f |
| 82 | |
| 83 | static const Vertex g_vbData[] = |
| 84 | { |
| 85 | { XYZ1( -1, -1, -1 ), XYZ1( 0.f, 0.f, 0.f ) }, |
| 86 | { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) }, |
| 87 | { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) }, |
| 88 | { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) }, |
| 89 | { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) }, |
| 90 | { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) }, |
| 91 | |
| 92 | { XYZ1( -1, -1, 1 ), XYZ1( 0.f, 0.f, 1.f ) }, |
| 93 | { XYZ1( -1, 1, 1 ), XYZ1( 0.f, 1.f, 1.f ) }, |
| 94 | { XYZ1( 1, -1, 1 ), XYZ1( 1.f, 0.f, 1.f ) }, |
| 95 | { XYZ1( 1, -1, 1 ), XYZ1( 1.f, 0.f, 1.f ) }, |
| 96 | { XYZ1( -1, 1, 1 ), XYZ1( 0.f, 1.f, 1.f ) }, |
| 97 | { XYZ1( 1, 1, 1 ), XYZ1( 1.f, 1.f, 1.f ) }, |
| 98 | |
| 99 | { XYZ1( 1, 1, 1 ), XYZ1( 1.f, 1.f, 1.f ) }, |
| 100 | { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) }, |
| 101 | { XYZ1( 1, -1, 1 ), XYZ1( 1.f, 0.f, 1.f ) }, |
| 102 | { XYZ1( 1, -1, 1 ), XYZ1( 1.f, 0.f, 1.f ) }, |
| 103 | { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) }, |
| 104 | { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) }, |
| 105 | |
| 106 | { XYZ1( -1, 1, 1 ), XYZ1( 0.f, 1.f, 1.f ) }, |
| 107 | { XYZ1( -1, -1, 1 ), XYZ1( 0.f, 0.f, 1.f ) }, |
| 108 | { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) }, |
| 109 | { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) }, |
| 110 | { XYZ1( -1, -1, 1 ), XYZ1( 0.f, 0.f, 1.f ) }, |
| 111 | { XYZ1( -1, -1, -1 ), XYZ1( 0.f, 0.f, 0.f ) }, |
| 112 | |
| 113 | { XYZ1( 1, 1, 1 ), XYZ1( 1.f, 1.f, 1.f ) }, |
| 114 | { XYZ1( -1, 1, 1 ), XYZ1( 0.f, 1.f, 1.f ) }, |
| 115 | { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) }, |
| 116 | { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) }, |
| 117 | { XYZ1( -1, 1, 1 ), XYZ1( 0.f, 1.f, 1.f ) }, |
| 118 | { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) }, |
| 119 | |
| 120 | { XYZ1( 1, -1, 1 ), XYZ1( 1.f, 0.f, 1.f ) }, |
| 121 | { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) }, |
| 122 | { XYZ1( -1, -1, 1 ), XYZ1( 0.f, 0.f, 1.f ) }, |
| 123 | { XYZ1( -1, -1, 1 ), XYZ1( 0.f, 0.f, 1.f ) }, |
| 124 | { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) }, |
| 125 | { XYZ1( -1, -1, -1 ), XYZ1( 0.f, 0.f, 0.f ) }, |
| 126 | }; |
| 127 | |
Chia-I Wu | 8759926 | 2014-08-30 14:03:32 +0800 | [diff] [blame] | 128 | static const uint32_t gen6_fs[] = { |
| 129 | 0x00600001, 0x202003fe, 0x00000000, 0x3f800000, // mov(8) m1<1>F 1F { align1 1Q }; |
| 130 | 0x00600001, 0x204003fe, 0x00000000, 0x00000000, // mov(8) m2<1>F 0F { align1 1Q }; |
| 131 | 0x00600001, 0x206003fe, 0x00000000, 0x00000000, // mov(8) m3<1>F 0F { align1 1Q }; |
| 132 | 0x00600001, 0x208003fe, 0x00000000, 0x3f800000, // mov(8) m4<1>F 1F { align1 1Q }; |
| 133 | 0x05600032, 0x20001fc8, 0x008d0020, 0x88019400, // sendc(8) null m1<8,8,1>F |
| 134 | // render RT write SIMD8 LastRT Surface = 0 mlen 4 rlen 0 { align1 1Q EOT }; |
| 135 | }; |
| 136 | |
| 137 | static const uint32_t gen6_vs[] = { |
| 138 | 0x01600110, 0x200f1ca4, 0x00600020, 0x00000000, // cmp.z.f0(8) null g1<4,4,1>.xD 0D { align16 1Q }; |
| 139 | 0x00670122, 0x000a108f, 0x000e0004, 0x000e0004, // (+f0.all4h) if(8) JIP: 10 { align16 1Q }; |
| 140 | 0x00600501, 0x204303fd, 0x00000000, 0xbf800000, // mov(8) g2<1>.xyF -1F { align16 NoDDClr 1Q }; |
| 141 | 0x00600d01, 0x204403fd, 0x00000000, 0x00000000, // mov(8) g2<1>.zF 0F { align16 NoDDClr,NoDDChk 1Q }; |
| 142 | 0x00600901, 0x204803fd, 0x00000000, 0x3f800000, // mov(8) g2<1>.wF 1F { align16 NoDDChk 1Q }; |
| 143 | 0x00600124, 0x0014108f, 0x006e0004, 0x006e0004, // else(8) JIP: 20 { align16 1Q }; |
| 144 | 0x01600110, 0x200f1ca4, 0x00600020, 0x00000001, // cmp.z.f0(8) null g1<4,4,1>.xD 1D { align16 1Q }; |
| 145 | 0x00670122, 0x000a108f, 0x000e0004, 0x000e0004, // (+f0.all4h) if(8) JIP: 10 { align16 1Q }; |
| 146 | 0x00600501, 0x204903fd, 0x00000000, 0x3f800000, // mov(8) g2<1>.xwF 1F { align16 NoDDClr 1Q }; |
| 147 | 0x00600d01, 0x204203fd, 0x00000000, 0xbf800000, // mov(8) g2<1>.yF -1F { align16 NoDDClr,NoDDChk 1Q }; |
| 148 | 0x00600901, 0x204403fd, 0x00000000, 0x00000000, // mov(8) g2<1>.zF 0F { align16 NoDDChk 1Q }; |
| 149 | 0x00600124, 0x0006108f, 0x006e0004, 0x006e0004, // else(8) JIP: 6 { align16 1Q }; |
| 150 | 0x00600501, 0x204503fd, 0x00000000, 0x00000000, // mov(8) g2<1>.xzF 0F { align16 NoDDClr 1Q }; |
| 151 | 0x00600901, 0x204a03fd, 0x00000000, 0x3f800000, // mov(8) g2<1>.ywF 1F { align16 NoDDChk 1Q }; |
| 152 | 0x00600125, 0x0002108f, 0x006e0004, 0x006e0002, // endif(8) JIP: 2 { align16 1Q }; |
| 153 | 0x00600125, 0x0002108f, 0x006e0004, 0x006e0002, // endif(8) JIP: 2 { align16 1Q }; |
| 154 | 0x00600101, 0x204f0062, 0x00000000, 0x00000000, // mov(8) m2<1>UD 0x00000000UD { align16 1Q }; |
| 155 | 0x00600101, 0x206f03be, 0x006e0044, 0x00000000, // mov(8) m3<1>F g2<4,4,1>F { align16 1Q }; |
| 156 | 0x00600301, 0x202f0022, 0x006e0004, 0x00000000, // mov(8) m1<1>UD g0<4,4,1>UD { align16 WE_all 1Q }; |
| 157 | 0x06600131, 0x200f1fdc, 0x006e0024, 0x8608c400, // send(8) null m1<4,4,1>F |
| 158 | // urb 0 urb_write interleave used complete mlen 3 rlen 0 { align16 1Q EOT }; |
| 159 | }; |
| 160 | |
| 161 | static const uint32_t gen7_fs[] = { |
| 162 | 0x00600001, 0x2e2003fd, 0x00000000, 0x3f800000, // mov(8) g113<1>F 1F { align1 1Q }; |
| 163 | 0x00600001, 0x2e4003fd, 0x00000000, 0x00000000, // mov(8) g114<1>F 0F { align1 1Q }; |
| 164 | 0x00600001, 0x2e6003fd, 0x00000000, 0x00000000, // mov(8) g115<1>F 0F { align1 1Q }; |
| 165 | 0x00600001, 0x2e8003fd, 0x00000000, 0x3f800000, // mov(8) g116<1>F 1F { align1 1Q }; |
| 166 | 0x05600032, 0x20001fa8, 0x008d0e20, 0x88031400, // sendc(8) null g113<8,8,1>F |
| 167 | // render RT write SIMD8 LastRT Surface = 0 mlen 4 rlen 0 { align1 1Q EOT }; |
| 168 | }; |
| 169 | |
| 170 | static const uint32_t gen7_vs[] = { |
| 171 | 0x01608110, 0x200f1ca4, 0x00600020, 0x00000000, // cmp.z.f0(8) null g1<4,4,1>.xD 0D { align16 1Q switch }; |
| 172 | 0x00670122, 0x200f0c84, 0x000e0004, 0x001c000a, // (+f0.all4h) if(8) JIP: 10 UIP: 28 { align16 1Q }; |
| 173 | 0x00600501, 0x204303fd, 0x00000000, 0xbf800000, // mov(8) g2<1>.xyF -1F { align16 NoDDClr 1Q }; |
| 174 | 0x00600d01, 0x204403fd, 0x00000000, 0x00000000, // mov(8) g2<1>.zF 0F { align16 NoDDClr,NoDDChk 1Q }; |
| 175 | 0x00600901, 0x204803fd, 0x00000000, 0x3f800000, // mov(8) g2<1>.wF 1F { align16 NoDDChk 1Q }; |
| 176 | 0x00600124, 0x200f0c84, 0x006e0004, 0x00000014, // else(8) JIP: 20 { align16 1Q }; |
| 177 | 0x01608110, 0x200f1ca4, 0x00600020, 0x00000001, // cmp.z.f0(8) null g1<4,4,1>.xD 1D { align16 1Q switch }; |
| 178 | 0x00670122, 0x200f0c84, 0x000e0004, 0x000e000a, // (+f0.all4h) if(8) JIP: 10 UIP: 14 { align16 1Q }; |
| 179 | 0x00600501, 0x204903fd, 0x00000000, 0x3f800000, // mov(8) g2<1>.xwF 1F { align16 NoDDClr 1Q }; |
| 180 | 0x00600d01, 0x204203fd, 0x00000000, 0xbf800000, // mov(8) g2<1>.yF -1F { align16 NoDDClr,NoDDChk 1Q }; |
| 181 | 0x00600901, 0x204403fd, 0x00000000, 0x00000000, // mov(8) g2<1>.zF 0F { align16 NoDDChk 1Q }; |
| 182 | 0x00600124, 0x200f0c84, 0x006e0004, 0x00000006, // else(8) JIP: 6 { align16 1Q }; |
| 183 | 0x00600501, 0x204503fd, 0x00000000, 0x00000000, // mov(8) g2<1>.xzF 0F { align16 NoDDClr 1Q }; |
| 184 | 0x00600901, 0x204a03fd, 0x00000000, 0x3f800000, // mov(8) g2<1>.ywF 1F { align16 NoDDChk 1Q }; |
| 185 | 0x00600125, 0x200f0c84, 0x006e0004, 0x00000002, // endif(8) JIP: 2 { align16 1Q }; |
| 186 | 0x00600125, 0x200f0c84, 0x006e0004, 0x00000002, // endif(8) JIP: 2 { align16 1Q }; |
| 187 | 0x00600101, 0x2e4f0061, 0x00000000, 0x00000000, // mov(8) g114<1>UD 0x00000000UD { align16 1Q }; |
| 188 | 0x00600101, 0x2e6f03bd, 0x006e0044, 0x00000000, // mov(8) g115<1>F g2<4,4,1>F { align16 1Q }; |
| 189 | 0x00600301, 0x2e2f0021, 0x006e0004, 0x00000000, // mov(8) g113<1>UD g0<4,4,1>UD { align16 WE_all 1Q }; |
| 190 | 0x00000206, 0x2e340c21, 0x00000014, 0x0000ff00, // or(1) g113.5<1>UD g0.5<0,1,0>UD 0x0000ff00UD { align1 WE_all }; |
| 191 | 0x06600131, 0x200f1fbc, 0x006e0e24, 0x8608c000, // send(8) null g113<4,4,1>F |
| 192 | // urb 0 write HWord interleave complete mlen 3 rlen 0 { align16 1Q EOT }; |
| 193 | }; |
Courtney Goeltzenleuchter | 0246188 | 2014-08-22 16:27:58 -0600 | [diff] [blame] | 194 | |
Courtney Goeltzenleuchter | cc5eb3a | 2014-08-19 18:35:50 -0600 | [diff] [blame] | 195 | class XglRenderTest : public ::testing::Test { |
| 196 | public: |
Courtney Goeltzenleuchter | 0246188 | 2014-08-22 16:27:58 -0600 | [diff] [blame] | 197 | void CreateImage(XGL_UINT w, XGL_UINT h, XGL_IMAGE *pImage, |
| 198 | XGL_GPU_MEMORY *pMem); |
Courtney Goeltzenleuchter | cc5eb3a | 2014-08-19 18:35:50 -0600 | [diff] [blame] | 199 | void DestroyImage(); |
| 200 | |
Chia-I Wu | 4e036a2 | 2014-08-30 23:53:01 +0800 | [diff] [blame] | 201 | void CreateQueryPool(XGL_QUERY_TYPE type, XGL_UINT slots, |
| 202 | XGL_QUERY_POOL *pPool, XGL_GPU_MEMORY *pMem); |
| 203 | void DestroyQueryPool(XGL_QUERY_POOL pool, XGL_GPU_MEMORY mem); |
| 204 | |
Courtney Goeltzenleuchter | cc5eb3a | 2014-08-19 18:35:50 -0600 | [diff] [blame] | 205 | void CreateImageView(XGL_IMAGE_VIEW_CREATE_INFO* pCreateInfo, |
| 206 | XGL_IMAGE_VIEW* pView); |
| 207 | void DestroyImageView(XGL_IMAGE_VIEW imageView); |
| 208 | XGL_DEVICE device() {return m_device->device();} |
Chia-I Wu | 8759926 | 2014-08-30 14:03:32 +0800 | [diff] [blame] | 209 | void CreateShader(XGL_PIPELINE_SHADER_STAGE stage, XGL_SHADER *pshader); |
Courtney Goeltzenleuchter | f56fdd4 | 2014-08-20 15:28:00 -0600 | [diff] [blame] | 210 | void InitPipeline(); |
Courtney Goeltzenleuchter | 0246188 | 2014-08-22 16:27:58 -0600 | [diff] [blame] | 211 | void InitMesh( XGL_UINT32 numVertices, XGL_GPU_SIZE vbStride, const void* vertices ); |
| 212 | void DrawTriangleTest(); |
Chia-I Wu | 113e9d9 | 2014-08-27 14:58:05 +0800 | [diff] [blame] | 213 | void WritePPM( const char *filename, int width, int height ); |
Courtney Goeltzenleuchter | f21d32d | 2014-09-01 13:57:15 -0600 | [diff] [blame] | 214 | DisplayEngine m_screen; |
Courtney Goeltzenleuchter | cc5eb3a | 2014-08-19 18:35:50 -0600 | [diff] [blame] | 215 | |
| 216 | protected: |
| 217 | XGL_APPLICATION_INFO app_info; |
| 218 | XGL_PHYSICAL_GPU objs[MAX_GPUS]; |
| 219 | XGL_UINT gpu_count; |
Courtney Goeltzenleuchter | 0246188 | 2014-08-22 16:27:58 -0600 | [diff] [blame] | 220 | XGL_IMAGE m_image; |
| 221 | XGL_IMAGE_STATE m_image_state; |
| 222 | XGL_GPU_MEMORY m_image_mem; |
| 223 | XGL_GPU_MEMORY m_descriptor_set_mem; |
| 224 | XGL_GPU_MEMORY m_pipe_mem; |
Courtney Goeltzenleuchter | cc5eb3a | 2014-08-19 18:35:50 -0600 | [diff] [blame] | 225 | XglDevice *m_device; |
Courtney Goeltzenleuchter | f56fdd4 | 2014-08-20 15:28:00 -0600 | [diff] [blame] | 226 | XGL_CMD_BUFFER m_cmdBuffer; |
Courtney Goeltzenleuchter | 0246188 | 2014-08-22 16:27:58 -0600 | [diff] [blame] | 227 | XGL_UINT32 m_numVertices; |
| 228 | XGL_MEMORY_VIEW_ATTACH_INFO m_vtxBufferView; |
| 229 | XGL_GPU_MEMORY m_vtxBufferMem; |
| 230 | XGL_UINT32 m_numMemRefs; |
| 231 | XGL_MEMORY_REF m_memRefs[5]; |
| 232 | XGL_RASTER_STATE_OBJECT m_stateRaster; |
Courtney Goeltzenleuchter | 464746c | 2014-08-26 18:16:41 -0600 | [diff] [blame] | 233 | XGL_COLOR_BLEND_STATE_OBJECT m_colorBlend; |
Courtney Goeltzenleuchter | 0246188 | 2014-08-22 16:27:58 -0600 | [diff] [blame] | 234 | XGL_VIEWPORT_STATE_OBJECT m_stateViewport; |
| 235 | XGL_DEPTH_STENCIL_STATE_OBJECT m_stateDepthStencil; |
| 236 | XGL_MSAA_STATE_OBJECT m_stateMsaa; |
| 237 | XGL_DESCRIPTOR_SET m_rsrcDescSet; |
Courtney Goeltzenleuchter | cc5eb3a | 2014-08-19 18:35:50 -0600 | [diff] [blame] | 238 | |
| 239 | virtual void SetUp() { |
| 240 | XGL_RESULT err; |
| 241 | |
| 242 | this->app_info.sType = XGL_STRUCTURE_TYPE_APPLICATION_INFO; |
| 243 | this->app_info.pNext = NULL; |
| 244 | this->app_info.pAppName = (const XGL_CHAR *) "base"; |
| 245 | this->app_info.appVersion = 1; |
| 246 | this->app_info.pEngineName = (const XGL_CHAR *) "unittest"; |
| 247 | this->app_info.engineVersion = 1; |
| 248 | this->app_info.apiVersion = XGL_MAKE_VERSION(0, 22, 0); |
| 249 | |
Courtney Goeltzenleuchter | 0246188 | 2014-08-22 16:27:58 -0600 | [diff] [blame] | 250 | memset(&m_vtxBufferView, 0, sizeof(m_vtxBufferView)); |
| 251 | m_vtxBufferView.sType = XGL_STRUCTURE_TYPE_MEMORY_VIEW_ATTACH_INFO; |
| 252 | |
Courtney Goeltzenleuchter | cc5eb3a | 2014-08-19 18:35:50 -0600 | [diff] [blame] | 253 | err = xglInitAndEnumerateGpus(&app_info, NULL, |
| 254 | MAX_GPUS, &this->gpu_count, objs); |
| 255 | ASSERT_XGL_SUCCESS(err); |
| 256 | ASSERT_GE(1, this->gpu_count) << "No GPU available"; |
| 257 | |
| 258 | m_device = new XglDevice(0, objs[0]); |
| 259 | m_device->get_device_queue(); |
| 260 | } |
| 261 | |
| 262 | virtual void TearDown() { |
| 263 | xglInitAndEnumerateGpus(&this->app_info, XGL_NULL_HANDLE, 0, &gpu_count, XGL_NULL_HANDLE); |
| 264 | } |
| 265 | }; |
| 266 | |
Courtney Goeltzenleuchter | 0246188 | 2014-08-22 16:27:58 -0600 | [diff] [blame] | 267 | void XglRenderTest::CreateImage(XGL_UINT w, XGL_UINT h, XGL_IMAGE *pImage, |
| 268 | XGL_GPU_MEMORY *pMem) |
Courtney Goeltzenleuchter | cc5eb3a | 2014-08-19 18:35:50 -0600 | [diff] [blame] | 269 | { |
| 270 | XGL_RESULT err; |
Courtney Goeltzenleuchter | cc5eb3a | 2014-08-19 18:35:50 -0600 | [diff] [blame] | 271 | XGL_UINT mipCount; |
| 272 | XGL_SIZE size; |
| 273 | XGL_FORMAT fmt; |
| 274 | XGL_FORMAT_PROPERTIES image_fmt; |
| 275 | |
| 276 | mipCount = 0; |
| 277 | |
Courtney Goeltzenleuchter | f21d32d | 2014-09-01 13:57:15 -0600 | [diff] [blame] | 278 | m_screen.Init(true, w, h); |
| 279 | |
Courtney Goeltzenleuchter | cc5eb3a | 2014-08-19 18:35:50 -0600 | [diff] [blame] | 280 | XGL_UINT _w = w; |
| 281 | XGL_UINT _h = h; |
| 282 | while( ( _w > 0 ) || ( _h > 0 ) ) |
| 283 | { |
| 284 | _w >>= 1; |
| 285 | _h >>= 1; |
| 286 | mipCount++; |
| 287 | } |
| 288 | |
| 289 | fmt.channelFormat = XGL_CH_FMT_R8G8B8A8; |
Chia-I Wu | 9d77725 | 2014-08-27 15:02:10 +0800 | [diff] [blame] | 290 | fmt.numericFormat = XGL_NUM_FMT_UNORM; |
Courtney Goeltzenleuchter | cc5eb3a | 2014-08-19 18:35:50 -0600 | [diff] [blame] | 291 | // TODO: Pick known good format rather than just expect common format |
| 292 | /* |
| 293 | * XXX: What should happen if given NULL HANDLE for the pData argument? |
| 294 | * We're not requesting XGL_INFO_TYPE_MEMORY_REQUIREMENTS so there is |
| 295 | * an expectation that pData is a valid pointer. |
| 296 | * However, why include a returned size value? That implies that the |
| 297 | * amount of data may vary and that doesn't work well for using a |
| 298 | * fixed structure. |
| 299 | */ |
| 300 | |
| 301 | err = xglGetFormatInfo(this->m_device->device(), fmt, |
| 302 | XGL_INFO_TYPE_FORMAT_PROPERTIES, |
| 303 | &size, &image_fmt); |
| 304 | ASSERT_XGL_SUCCESS(err); |
| 305 | |
| 306 | // typedef struct _XGL_IMAGE_CREATE_INFO |
| 307 | // { |
| 308 | // XGL_STRUCTURE_TYPE sType; // Must be XGL_STRUCTURE_TYPE_IMAGE_CREATE_INFO |
| 309 | // const XGL_VOID* pNext; // Pointer to next structure. |
| 310 | // XGL_IMAGE_TYPE imageType; |
| 311 | // XGL_FORMAT format; |
| 312 | // XGL_EXTENT3D extent; |
| 313 | // XGL_UINT mipLevels; |
| 314 | // XGL_UINT arraySize; |
| 315 | // XGL_UINT samples; |
| 316 | // XGL_IMAGE_TILING tiling; |
| 317 | // XGL_FLAGS usage; // XGL_IMAGE_USAGE_FLAGS |
| 318 | // XGL_FLAGS flags; // XGL_IMAGE_CREATE_FLAGS |
| 319 | // } XGL_IMAGE_CREATE_INFO; |
| 320 | |
| 321 | |
| 322 | XGL_IMAGE_CREATE_INFO imageCreateInfo = {}; |
| 323 | imageCreateInfo.sType = XGL_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 324 | imageCreateInfo.imageType = XGL_IMAGE_2D; |
| 325 | imageCreateInfo.format = fmt; |
| 326 | imageCreateInfo.arraySize = 1; |
| 327 | imageCreateInfo.extent.width = w; |
| 328 | imageCreateInfo.extent.height = h; |
| 329 | imageCreateInfo.extent.depth = 1; |
| 330 | imageCreateInfo.mipLevels = mipCount; |
| 331 | imageCreateInfo.samples = 1; |
| 332 | imageCreateInfo.tiling = XGL_LINEAR_TILING; |
| 333 | |
| 334 | // Image usage flags |
| 335 | // typedef enum _XGL_IMAGE_USAGE_FLAGS |
| 336 | // { |
| 337 | // XGL_IMAGE_USAGE_SHADER_ACCESS_READ_BIT = 0x00000001, |
| 338 | // XGL_IMAGE_USAGE_SHADER_ACCESS_WRITE_BIT = 0x00000002, |
| 339 | // XGL_IMAGE_USAGE_COLOR_ATTACHMENT_BIT = 0x00000004, |
| 340 | // XGL_IMAGE_USAGE_DEPTH_STENCIL_BIT = 0x00000008, |
| 341 | // } XGL_IMAGE_USAGE_FLAGS; |
| 342 | imageCreateInfo.usage = XGL_IMAGE_USAGE_SHADER_ACCESS_WRITE_BIT | XGL_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; |
| 343 | |
| 344 | // XGL_RESULT XGLAPI xglCreateImage( |
| 345 | // XGL_DEVICE device, |
| 346 | // const XGL_IMAGE_CREATE_INFO* pCreateInfo, |
| 347 | // XGL_IMAGE* pImage); |
Courtney Goeltzenleuchter | 0246188 | 2014-08-22 16:27:58 -0600 | [diff] [blame] | 348 | err = xglCreateImage(device(), &imageCreateInfo, pImage); |
Courtney Goeltzenleuchter | cc5eb3a | 2014-08-19 18:35:50 -0600 | [diff] [blame] | 349 | ASSERT_XGL_SUCCESS(err); |
| 350 | |
| 351 | XGL_MEMORY_REQUIREMENTS mem_req; |
| 352 | XGL_UINT data_size; |
Courtney Goeltzenleuchter | 0246188 | 2014-08-22 16:27:58 -0600 | [diff] [blame] | 353 | err = xglGetObjectInfo(*pImage, XGL_INFO_TYPE_MEMORY_REQUIREMENTS, |
Courtney Goeltzenleuchter | cc5eb3a | 2014-08-19 18:35:50 -0600 | [diff] [blame] | 354 | &data_size, &mem_req); |
| 355 | ASSERT_XGL_SUCCESS(err); |
| 356 | ASSERT_EQ(data_size, sizeof(mem_req)); |
| 357 | ASSERT_NE(0, mem_req.size) << "xglGetObjectInfo (Event): Failed - expect images to require memory"; |
| 358 | |
Courtney Goeltzenleuchter | 0246188 | 2014-08-22 16:27:58 -0600 | [diff] [blame] | 359 | m_image_state = XGL_IMAGE_STATE_UNINITIALIZED_TARGET; |
| 360 | |
Courtney Goeltzenleuchter | cc5eb3a | 2014-08-19 18:35:50 -0600 | [diff] [blame] | 361 | // XGL_RESULT XGLAPI xglAllocMemory( |
| 362 | // XGL_DEVICE device, |
| 363 | // const XGL_MEMORY_ALLOC_INFO* pAllocInfo, |
| 364 | // XGL_GPU_MEMORY* pMem); |
| 365 | XGL_MEMORY_ALLOC_INFO mem_info; |
| 366 | |
| 367 | memset(&mem_info, 0, sizeof(mem_info)); |
| 368 | mem_info.sType = XGL_STRUCTURE_TYPE_MEMORY_ALLOC_INFO; |
| 369 | mem_info.allocationSize = mem_req.size; |
| 370 | mem_info.alignment = mem_req.alignment; |
| 371 | mem_info.heapCount = mem_req.heapCount; |
| 372 | memcpy(mem_info.heaps, mem_req.heaps, sizeof(XGL_UINT)*XGL_MAX_MEMORY_HEAPS); |
| 373 | mem_info.memPriority = XGL_MEMORY_PRIORITY_NORMAL; |
| 374 | mem_info.flags = XGL_MEMORY_ALLOC_SHAREABLE_BIT; |
Courtney Goeltzenleuchter | 0246188 | 2014-08-22 16:27:58 -0600 | [diff] [blame] | 375 | err = xglAllocMemory(device(), &mem_info, pMem); |
Courtney Goeltzenleuchter | cc5eb3a | 2014-08-19 18:35:50 -0600 | [diff] [blame] | 376 | ASSERT_XGL_SUCCESS(err); |
| 377 | |
Courtney Goeltzenleuchter | 0246188 | 2014-08-22 16:27:58 -0600 | [diff] [blame] | 378 | err = xglBindObjectMemory(*pImage, *pMem, 0); |
Courtney Goeltzenleuchter | cc5eb3a | 2014-08-19 18:35:50 -0600 | [diff] [blame] | 379 | ASSERT_XGL_SUCCESS(err); |
| 380 | } |
| 381 | |
| 382 | void XglRenderTest::DestroyImage() |
| 383 | { |
| 384 | // All done with image memory, clean up |
| 385 | ASSERT_XGL_SUCCESS(xglBindObjectMemory(m_image, XGL_NULL_HANDLE, 0)); |
| 386 | |
| 387 | ASSERT_XGL_SUCCESS(xglFreeMemory(m_image_mem)); |
| 388 | |
| 389 | ASSERT_XGL_SUCCESS(xglDestroyObject(m_image)); |
| 390 | } |
| 391 | |
Chia-I Wu | 4e036a2 | 2014-08-30 23:53:01 +0800 | [diff] [blame] | 392 | void XglRenderTest::CreateQueryPool(XGL_QUERY_TYPE type, XGL_UINT slots, |
| 393 | XGL_QUERY_POOL *pPool, XGL_GPU_MEMORY *pMem) |
| 394 | { |
| 395 | XGL_RESULT err; |
| 396 | |
| 397 | XGL_QUERY_POOL_CREATE_INFO poolCreateInfo = {}; |
| 398 | poolCreateInfo.sType = XGL_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO; |
| 399 | poolCreateInfo.pNext = NULL; |
| 400 | poolCreateInfo.queryType = type; |
| 401 | poolCreateInfo.slots = slots; |
| 402 | |
| 403 | err = xglCreateQueryPool(device(), &poolCreateInfo, pPool); |
| 404 | ASSERT_XGL_SUCCESS(err); |
| 405 | |
| 406 | XGL_MEMORY_REQUIREMENTS mem_req; |
| 407 | XGL_UINT data_size; |
| 408 | err = xglGetObjectInfo(*pPool, XGL_INFO_TYPE_MEMORY_REQUIREMENTS, |
| 409 | &data_size, &mem_req); |
| 410 | ASSERT_XGL_SUCCESS(err); |
| 411 | ASSERT_EQ(data_size, sizeof(mem_req)); |
| 412 | |
| 413 | if (!mem_req.size) { |
| 414 | *pMem = XGL_NULL_HANDLE; |
| 415 | return; |
| 416 | } |
| 417 | |
| 418 | XGL_MEMORY_ALLOC_INFO mem_info; |
| 419 | |
| 420 | memset(&mem_info, 0, sizeof(mem_info)); |
| 421 | mem_info.sType = XGL_STRUCTURE_TYPE_MEMORY_ALLOC_INFO; |
| 422 | mem_info.allocationSize = mem_req.size; |
| 423 | mem_info.alignment = mem_req.alignment; |
| 424 | mem_info.heapCount = mem_req.heapCount; |
| 425 | memcpy(mem_info.heaps, mem_req.heaps, sizeof(XGL_UINT)*XGL_MAX_MEMORY_HEAPS); |
| 426 | mem_info.memPriority = XGL_MEMORY_PRIORITY_NORMAL; |
| 427 | mem_info.flags = XGL_MEMORY_ALLOC_SHAREABLE_BIT; |
| 428 | err = xglAllocMemory(device(), &mem_info, pMem); |
| 429 | ASSERT_XGL_SUCCESS(err); |
| 430 | |
| 431 | err = xglBindObjectMemory(*pPool, *pMem, 0); |
| 432 | ASSERT_XGL_SUCCESS(err); |
| 433 | } |
| 434 | |
| 435 | void XglRenderTest::DestroyQueryPool(XGL_QUERY_POOL pool, XGL_GPU_MEMORY mem) |
| 436 | { |
| 437 | ASSERT_XGL_SUCCESS(xglBindObjectMemory(pool, XGL_NULL_HANDLE, 0)); |
| 438 | ASSERT_XGL_SUCCESS(xglFreeMemory(mem)); |
| 439 | ASSERT_XGL_SUCCESS(xglDestroyObject(pool)); |
| 440 | } |
| 441 | |
Courtney Goeltzenleuchter | cc5eb3a | 2014-08-19 18:35:50 -0600 | [diff] [blame] | 442 | void XglRenderTest::CreateImageView(XGL_IMAGE_VIEW_CREATE_INFO *pCreateInfo, |
| 443 | XGL_IMAGE_VIEW *pView) |
| 444 | { |
| 445 | pCreateInfo->image = this->m_image; |
| 446 | ASSERT_XGL_SUCCESS(xglCreateImageView(device(), pCreateInfo, pView)); |
| 447 | } |
| 448 | |
| 449 | void XglRenderTest::DestroyImageView(XGL_IMAGE_VIEW imageView) |
| 450 | { |
| 451 | ASSERT_XGL_SUCCESS(xglDestroyObject(imageView)); |
| 452 | } |
| 453 | |
Chia-I Wu | 8759926 | 2014-08-30 14:03:32 +0800 | [diff] [blame] | 454 | void XglRenderTest::CreateShader(XGL_PIPELINE_SHADER_STAGE stage, XGL_SHADER *pshader) |
Courtney Goeltzenleuchter | f56fdd4 | 2014-08-20 15:28:00 -0600 | [diff] [blame] | 455 | { |
Chia-I Wu | d1e7bf9 | 2014-08-28 12:27:21 +0800 | [diff] [blame] | 456 | struct icd_bil_header *pBIL; |
Courtney Goeltzenleuchter | da91b95 | 2014-08-21 17:34:22 -0600 | [diff] [blame] | 457 | char * memblock; |
Chia-I Wu | 8759926 | 2014-08-30 14:03:32 +0800 | [diff] [blame] | 458 | const char *kernel; |
| 459 | size_t kernel_size; |
Courtney Goeltzenleuchter | cc5eb3a | 2014-08-19 18:35:50 -0600 | [diff] [blame] | 460 | XGL_RESULT err; |
| 461 | |
Chia-I Wu | 8759926 | 2014-08-30 14:03:32 +0800 | [diff] [blame] | 462 | const XGL_PHYSICAL_GPU_PROPERTIES *props = &m_device->props; |
| 463 | const int gen = (strstr((const char *) props->gpuName, "Sandybridge")) ? 6 : 7; |
Courtney Goeltzenleuchter | cc5eb3a | 2014-08-19 18:35:50 -0600 | [diff] [blame] | 464 | |
Chia-I Wu | 8759926 | 2014-08-30 14:03:32 +0800 | [diff] [blame] | 465 | if (stage == XGL_SHADER_STAGE_VERTEX) { |
| 466 | if (gen == 6) { |
| 467 | kernel = (const char *) gen6_vs; |
| 468 | kernel_size = sizeof(gen6_vs); |
| 469 | } else { |
| 470 | kernel = (const char *) gen7_vs; |
| 471 | kernel_size = sizeof(gen7_vs); |
| 472 | } |
| 473 | } else { |
| 474 | if (gen == 6) { |
| 475 | kernel = (const char *) gen6_fs; |
| 476 | kernel_size = sizeof(gen6_fs); |
| 477 | } else { |
| 478 | kernel = (const char *) gen7_fs; |
| 479 | kernel_size = sizeof(gen7_fs); |
| 480 | } |
| 481 | } |
Courtney Goeltzenleuchter | cc5eb3a | 2014-08-19 18:35:50 -0600 | [diff] [blame] | 482 | |
Chia-I Wu | 8759926 | 2014-08-30 14:03:32 +0800 | [diff] [blame] | 483 | memblock = new char [sizeof(*pBIL) + kernel_size]; |
Courtney Goeltzenleuchter | 0246188 | 2014-08-22 16:27:58 -0600 | [diff] [blame] | 484 | ASSERT_TRUE(memblock != NULL) << "memory allocation failed"; |
Courtney Goeltzenleuchter | cc5eb3a | 2014-08-19 18:35:50 -0600 | [diff] [blame] | 485 | |
Chia-I Wu | d1e7bf9 | 2014-08-28 12:27:21 +0800 | [diff] [blame] | 486 | pBIL = (struct icd_bil_header *) memblock; |
| 487 | pBIL->magic = ICD_BIL_MAGIC; |
| 488 | pBIL->version = ICD_BIL_VERSION; |
| 489 | |
Chia-I Wu | 8759926 | 2014-08-30 14:03:32 +0800 | [diff] [blame] | 490 | pBIL->gen_magic = (stage == XGL_SHADER_STAGE_VERTEX) ? 'v' : 'w'; |
| 491 | memcpy(pBIL + 1, kernel, kernel_size); |
Chia-I Wu | d1e7bf9 | 2014-08-28 12:27:21 +0800 | [diff] [blame] | 492 | |
Courtney Goeltzenleuchter | 0246188 | 2014-08-22 16:27:58 -0600 | [diff] [blame] | 493 | XGL_SHADER_CREATE_INFO createInfo; |
| 494 | XGL_SHADER shader; |
Courtney Goeltzenleuchter | da91b95 | 2014-08-21 17:34:22 -0600 | [diff] [blame] | 495 | |
Courtney Goeltzenleuchter | 0246188 | 2014-08-22 16:27:58 -0600 | [diff] [blame] | 496 | createInfo.sType = XGL_STRUCTURE_TYPE_SHADER_CREATE_INFO; |
| 497 | createInfo.pNext = NULL; |
| 498 | createInfo.pCode = memblock; |
Chia-I Wu | 8759926 | 2014-08-30 14:03:32 +0800 | [diff] [blame] | 499 | createInfo.codeSize = sizeof(*pBIL) + kernel_size; |
Courtney Goeltzenleuchter | 0246188 | 2014-08-22 16:27:58 -0600 | [diff] [blame] | 500 | createInfo.flags = 0; |
| 501 | err = xglCreateShader(device(), &createInfo, &shader); |
| 502 | ASSERT_XGL_SUCCESS(err); |
Courtney Goeltzenleuchter | da91b95 | 2014-08-21 17:34:22 -0600 | [diff] [blame] | 503 | |
Courtney Goeltzenleuchter | 0246188 | 2014-08-22 16:27:58 -0600 | [diff] [blame] | 504 | delete[] memblock; |
Courtney Goeltzenleuchter | da91b95 | 2014-08-21 17:34:22 -0600 | [diff] [blame] | 505 | |
Courtney Goeltzenleuchter | 0246188 | 2014-08-22 16:27:58 -0600 | [diff] [blame] | 506 | *pshader = shader; |
Courtney Goeltzenleuchter | f56fdd4 | 2014-08-20 15:28:00 -0600 | [diff] [blame] | 507 | } |
Courtney Goeltzenleuchter | cc5eb3a | 2014-08-19 18:35:50 -0600 | [diff] [blame] | 508 | |
Courtney Goeltzenleuchter | 0246188 | 2014-08-22 16:27:58 -0600 | [diff] [blame] | 509 | // this function will create the vertex buffer and fill it with the mesh data |
| 510 | void XglRenderTest::InitMesh( XGL_UINT32 numVertices, XGL_GPU_SIZE vbStride, |
| 511 | const void* vertices ) |
| 512 | { |
| 513 | XGL_RESULT err = XGL_SUCCESS; |
| 514 | |
| 515 | assert( numVertices * vbStride > 0 ); |
| 516 | m_numVertices = numVertices; |
| 517 | |
| 518 | XGL_MEMORY_ALLOC_INFO alloc_info = {}; |
| 519 | XGL_UINT8 *pData; |
| 520 | |
| 521 | alloc_info.sType = XGL_STRUCTURE_TYPE_MEMORY_ALLOC_INFO; |
| 522 | alloc_info.allocationSize = numVertices * vbStride; |
| 523 | alloc_info.alignment = 0; |
| 524 | alloc_info.heapCount = 1; |
| 525 | alloc_info.heaps[0] = 0; // TODO: Use known existing heap |
| 526 | |
| 527 | alloc_info.flags = XGL_MEMORY_HEAP_CPU_VISIBLE_BIT; |
| 528 | alloc_info.memPriority = XGL_MEMORY_PRIORITY_NORMAL; |
| 529 | |
| 530 | err = xglAllocMemory(device(), &alloc_info, &m_vtxBufferMem); |
| 531 | ASSERT_XGL_SUCCESS(err); |
| 532 | |
| 533 | err = xglMapMemory(m_vtxBufferMem, 0, (XGL_VOID **) &pData); |
| 534 | ASSERT_XGL_SUCCESS(err); |
| 535 | |
| 536 | memcpy(pData, vertices, alloc_info.allocationSize); |
| 537 | |
| 538 | err = xglUnmapMemory(m_vtxBufferMem); |
| 539 | ASSERT_XGL_SUCCESS(err); |
| 540 | |
| 541 | // set up the memory view for the vertex buffer |
| 542 | this->m_vtxBufferView.stride = vbStride; |
| 543 | this->m_vtxBufferView.range = numVertices * vbStride; |
| 544 | this->m_vtxBufferView.offset = 0; |
| 545 | this->m_vtxBufferView.mem = m_vtxBufferMem; |
| 546 | this->m_vtxBufferView.format.channelFormat = XGL_CH_FMT_UNDEFINED; |
| 547 | this->m_vtxBufferView.format.numericFormat = XGL_NUM_FMT_UNDEFINED; |
| 548 | |
| 549 | // open the command buffer |
| 550 | err = xglBeginCommandBuffer( m_cmdBuffer, 0 ); |
| 551 | ASSERT_XGL_SUCCESS(err); |
| 552 | |
| 553 | XGL_MEMORY_STATE_TRANSITION transition = {}; |
| 554 | transition.mem = m_vtxBufferMem; |
| 555 | transition.oldState = XGL_MEMORY_STATE_DATA_TRANSFER; |
| 556 | transition.newState = XGL_MEMORY_STATE_GRAPHICS_SHADER_READ_ONLY; |
| 557 | transition.offset = 0; |
| 558 | transition.regionSize = numVertices * vbStride; |
| 559 | |
| 560 | // write transition to the command buffer |
| 561 | xglCmdPrepareMemoryRegions( m_cmdBuffer, 1, &transition ); |
| 562 | this->m_vtxBufferView.state = XGL_MEMORY_STATE_GRAPHICS_SHADER_READ_ONLY; |
| 563 | |
| 564 | // finish recording the command buffer |
| 565 | err = xglEndCommandBuffer( m_cmdBuffer ); |
| 566 | ASSERT_XGL_SUCCESS(err); |
| 567 | |
| 568 | // this command buffer only uses the vertex buffer memory |
| 569 | m_numMemRefs = 1; |
| 570 | m_memRefs[0].flags = 0; |
| 571 | m_memRefs[0].mem = m_vtxBufferMem; |
| 572 | |
| 573 | // submit the command buffer to the universal queue |
| 574 | err = xglQueueSubmit( m_device->m_queue, 1, &m_cmdBuffer, m_numMemRefs, m_memRefs, NULL ); |
| 575 | ASSERT_XGL_SUCCESS(err); |
| 576 | } |
| 577 | |
| 578 | void XglRenderTest::DrawTriangleTest() |
| 579 | { |
Courtney Goeltzenleuchter | f56fdd4 | 2014-08-20 15:28:00 -0600 | [diff] [blame] | 580 | XGL_RESULT err; |
| 581 | XGL_GRAPHICS_PIPELINE_CREATE_INFO info = {}; |
| 582 | XGL_SHADER vs, ps; |
| 583 | XGL_PIPELINE_SHADER_STAGE_CREATE_INFO vs_stage; |
| 584 | XGL_PIPELINE_SHADER_STAGE_CREATE_INFO ps_stage; |
| 585 | XGL_PIPELINE pipeline; |
Courtney Goeltzenleuchter | 0246188 | 2014-08-22 16:27:58 -0600 | [diff] [blame] | 586 | int width = 256, height = 256; |
Courtney Goeltzenleuchter | cc5eb3a | 2014-08-19 18:35:50 -0600 | [diff] [blame] | 587 | |
Courtney Goeltzenleuchter | 0246188 | 2014-08-22 16:27:58 -0600 | [diff] [blame] | 588 | // create a raster state (solid, back-face culling) |
| 589 | XGL_RASTER_STATE_CREATE_INFO raster = {}; |
| 590 | raster.sType = XGL_STRUCTURE_TYPE_RASTER_STATE_CREATE_INFO; |
| 591 | raster.fillMode = XGL_FILL_SOLID; |
Chia-I Wu | 0685cb1 | 2014-08-31 00:52:42 +0800 | [diff] [blame] | 592 | raster.cullMode = XGL_CULL_NONE; |
Courtney Goeltzenleuchter | 0246188 | 2014-08-22 16:27:58 -0600 | [diff] [blame] | 593 | raster.frontFace = XGL_FRONT_FACE_CCW; |
| 594 | err = xglCreateRasterState( device(), &raster, &m_stateRaster ); |
| 595 | ASSERT_XGL_SUCCESS(err); |
| 596 | |
| 597 | XGL_VIEWPORT_STATE_CREATE_INFO viewport = {}; |
| 598 | viewport.viewportCount = 1; |
| 599 | viewport.scissorEnable = XGL_FALSE; |
| 600 | viewport.viewports[0].originX = 0; |
| 601 | viewport.viewports[0].originY = 0; |
| 602 | viewport.viewports[0].width = 1.f * width; |
| 603 | viewport.viewports[0].height = 1.f * height; |
| 604 | viewport.viewports[0].minDepth = 0.f; |
| 605 | viewport.viewports[0].maxDepth = 1.f; |
| 606 | |
| 607 | err = xglCreateViewportState( device(), &viewport, &m_stateViewport ); |
| 608 | ASSERT_XGL_SUCCESS( err ); |
| 609 | |
Courtney Goeltzenleuchter | 464746c | 2014-08-26 18:16:41 -0600 | [diff] [blame] | 610 | XGL_COLOR_BLEND_STATE_CREATE_INFO blend = {}; |
| 611 | blend.sType = XGL_STRUCTURE_TYPE_COLOR_BLEND_STATE_CREATE_INFO; |
| 612 | err = xglCreateColorBlendState(device(), &blend, &m_colorBlend); |
| 613 | ASSERT_XGL_SUCCESS( err ); |
| 614 | |
Courtney Goeltzenleuchter | 0246188 | 2014-08-22 16:27:58 -0600 | [diff] [blame] | 615 | XGL_DEPTH_STENCIL_STATE_CREATE_INFO depthStencil = {}; |
| 616 | depthStencil.sType = XGL_STRUCTURE_TYPE_DEPTH_STENCIL_STATE_CREATE_INFO; |
| 617 | depthStencil.depthTestEnable = XGL_FALSE; |
| 618 | depthStencil.depthWriteEnable = XGL_FALSE; |
| 619 | depthStencil.depthFunc = XGL_COMPARE_LESS_EQUAL; |
| 620 | depthStencil.depthBoundsEnable = XGL_FALSE; |
| 621 | depthStencil.minDepth = 0.f; |
| 622 | depthStencil.maxDepth = 1.f; |
| 623 | depthStencil.back.stencilDepthFailOp = XGL_STENCIL_OP_KEEP; |
| 624 | depthStencil.back.stencilFailOp = XGL_STENCIL_OP_KEEP; |
| 625 | depthStencil.back.stencilPassOp = XGL_STENCIL_OP_KEEP; |
| 626 | depthStencil.back.stencilRef = 0x00; |
| 627 | depthStencil.back.stencilFunc = XGL_COMPARE_ALWAYS; |
| 628 | depthStencil.front = depthStencil.back; |
| 629 | |
| 630 | err = xglCreateDepthStencilState( device(), &depthStencil, &m_stateDepthStencil ); |
| 631 | ASSERT_XGL_SUCCESS( err ); |
| 632 | |
| 633 | XGL_MSAA_STATE_CREATE_INFO msaa = {}; |
| 634 | msaa.sType = XGL_STRUCTURE_TYPE_MSAA_STATE_CREATE_INFO; |
| 635 | msaa.sampleMask = 1; |
| 636 | msaa.samples = 1; |
| 637 | |
| 638 | err = xglCreateMsaaState( device(), &msaa, &m_stateMsaa ); |
| 639 | ASSERT_XGL_SUCCESS( err ); |
| 640 | |
| 641 | XGL_CMD_BUFFER_CREATE_INFO cmdInfo = {}; |
| 642 | |
| 643 | cmdInfo.sType = XGL_STRUCTURE_TYPE_CMD_BUFFER_CREATE_INFO; |
| 644 | cmdInfo.queueType = XGL_QUEUE_TYPE_GRAPHICS; |
| 645 | err = xglCreateCommandBuffer(device(), &cmdInfo, &m_cmdBuffer); |
| 646 | ASSERT_XGL_SUCCESS(err) << "xglCreateCommandBuffer failed"; |
| 647 | |
| 648 | ASSERT_NO_FATAL_FAILURE(CreateImage(width, height, &m_image, &m_image_mem)); |
| 649 | |
| 650 | #if 0 |
| 651 | // Create descriptor set for our one resource |
| 652 | XGL_DESCRIPTOR_SET_CREATE_INFO descriptorInfo = {}; |
| 653 | descriptorInfo.sType = XGL_STRUCTURE_TYPE_DESCRIPTOR_SET_CREATE_INFO; |
| 654 | descriptorInfo.slots = 1; // Vertex buffer only |
| 655 | |
| 656 | // create a descriptor set with a single slot |
| 657 | err = xglCreateDescriptorSet( device(), &descriptorInfo, &m_rsrcDescSet ); |
| 658 | ASSERT_XGL_SUCCESS(err) << "xglCreateDescriptorSet failed"; |
| 659 | |
| 660 | // bind memory to the descriptor set |
| 661 | err = m_device->AllocAndBindGpuMemory(m_rsrcDescSet, "DescriptorSet", &m_descriptor_set_mem); |
| 662 | |
| 663 | // set up the memory view for the vertex buffer |
| 664 | this->m_vtxBufferView.stride = vbStride; |
| 665 | this->m_vtxBufferView.range = numVertices * vbStride; |
| 666 | this->m_vtxBufferView.offset = 0; |
| 667 | this->m_vtxBufferView.mem = m_vtxBufferMem; |
| 668 | this->m_vtxBufferView.format.channelFormat = XGL_CH_FMT_UNDEFINED; |
| 669 | this->m_vtxBufferView.format.numericFormat = XGL_NUM_FMT_UNDEFINED; |
| 670 | // write the vertex buffer view to the descriptor set |
| 671 | xglBeginDescriptorSetUpdate( m_rsrcDescSet ); |
| 672 | xglAttachMemoryViewDescriptors( m_rsrcDescSet, 0, 1, &m_vtxBufferView ); |
| 673 | xglEndDescriptorSetUpdate( m_rsrcDescSet ); |
| 674 | #endif |
Courtney Goeltzenleuchter | f56fdd4 | 2014-08-20 15:28:00 -0600 | [diff] [blame] | 675 | |
Chia-I Wu | 8759926 | 2014-08-30 14:03:32 +0800 | [diff] [blame] | 676 | ASSERT_NO_FATAL_FAILURE(CreateShader(XGL_SHADER_STAGE_VERTEX, &vs)); |
Courtney Goeltzenleuchter | f56fdd4 | 2014-08-20 15:28:00 -0600 | [diff] [blame] | 677 | |
| 678 | vs_stage.sType = XGL_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; |
| 679 | vs_stage.pNext = XGL_NULL_HANDLE; |
| 680 | vs_stage.shader.stage = XGL_SHADER_STAGE_VERTEX; |
| 681 | vs_stage.shader.shader = vs; |
Chia-I Wu | 619ab2b | 2014-08-23 17:47:45 +0800 | [diff] [blame] | 682 | vs_stage.shader.descriptorSetMapping[0].descriptorCount = 0; |
Courtney Goeltzenleuchter | f56fdd4 | 2014-08-20 15:28:00 -0600 | [diff] [blame] | 683 | vs_stage.shader.linkConstBufferCount = 0; |
| 684 | vs_stage.shader.pLinkConstBufferInfo = XGL_NULL_HANDLE; |
Chia-I Wu | 619ab2b | 2014-08-23 17:47:45 +0800 | [diff] [blame] | 685 | vs_stage.shader.dynamicMemoryViewMapping.slotObjectType = XGL_SLOT_UNUSED; |
Courtney Goeltzenleuchter | f56fdd4 | 2014-08-20 15:28:00 -0600 | [diff] [blame] | 686 | vs_stage.shader.dynamicMemoryViewMapping.shaderEntityIndex = 0; |
| 687 | |
Chia-I Wu | 8759926 | 2014-08-30 14:03:32 +0800 | [diff] [blame] | 688 | ASSERT_NO_FATAL_FAILURE(CreateShader(XGL_SHADER_STAGE_FRAGMENT, &ps)); |
Courtney Goeltzenleuchter | f56fdd4 | 2014-08-20 15:28:00 -0600 | [diff] [blame] | 689 | |
| 690 | ps_stage.sType = XGL_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; |
| 691 | ps_stage.pNext = &vs_stage; |
| 692 | ps_stage.shader.stage = XGL_SHADER_STAGE_FRAGMENT; |
| 693 | ps_stage.shader.shader = ps; |
Courtney Goeltzenleuchter | f56fdd4 | 2014-08-20 15:28:00 -0600 | [diff] [blame] | 694 | // TODO: Do we need a descriptor set mapping for fragment? |
Chia-I Wu | 619ab2b | 2014-08-23 17:47:45 +0800 | [diff] [blame] | 695 | ps_stage.shader.descriptorSetMapping[0].descriptorCount = 0; |
Courtney Goeltzenleuchter | f56fdd4 | 2014-08-20 15:28:00 -0600 | [diff] [blame] | 696 | ps_stage.shader.linkConstBufferCount = 0; |
| 697 | ps_stage.shader.pLinkConstBufferInfo = XGL_NULL_HANDLE; |
Chia-I Wu | 619ab2b | 2014-08-23 17:47:45 +0800 | [diff] [blame] | 698 | ps_stage.shader.dynamicMemoryViewMapping.slotObjectType = XGL_SLOT_UNUSED; |
Courtney Goeltzenleuchter | f56fdd4 | 2014-08-20 15:28:00 -0600 | [diff] [blame] | 699 | ps_stage.shader.dynamicMemoryViewMapping.shaderEntityIndex = 0; |
| 700 | |
| 701 | XGL_PIPELINE_IA_STATE_CREATE_INFO ia_state = { |
| 702 | XGL_STRUCTURE_TYPE_PIPELINE_IA_STATE_CREATE_INFO, // sType |
| 703 | &ps_stage, // pNext |
| 704 | XGL_TOPOLOGY_TRIANGLE_LIST, // XGL_PRIMITIVE_TOPOLOGY |
| 705 | XGL_FALSE, // disableVertexReuse |
| 706 | XGL_PROVOKING_VERTEX_LAST, // XGL_PROVOKING_VERTEX_CONVENTION |
| 707 | XGL_FALSE, // primitiveRestartEnable |
| 708 | 0 // primitiveRestartIndex |
| 709 | }; |
| 710 | |
| 711 | XGL_PIPELINE_RS_STATE_CREATE_INFO rs_state = { |
| 712 | XGL_STRUCTURE_TYPE_PIPELINE_RS_STATE_CREATE_INFO, |
| 713 | &ia_state, |
| 714 | XGL_FALSE, // depthClipEnable |
| 715 | XGL_FALSE, // rasterizerDiscardEnable |
| 716 | 1.0 // pointSize |
| 717 | }; |
| 718 | |
| 719 | XGL_PIPELINE_CB_STATE cb_state = { |
| 720 | XGL_STRUCTURE_TYPE_PIPELINE_CB_STATE_CREATE_INFO, |
| 721 | &rs_state, |
| 722 | XGL_FALSE, // alphaToCoverageEnable |
| 723 | XGL_FALSE, // dualSourceBlendEnable |
| 724 | XGL_LOGIC_OP_COPY, // XGL_LOGIC_OP |
| 725 | { // XGL_PIPELINE_CB_ATTACHMENT_STATE |
| 726 | { |
| 727 | XGL_FALSE, // blendEnable |
Chia-I Wu | 9d77725 | 2014-08-27 15:02:10 +0800 | [diff] [blame] | 728 | {XGL_CH_FMT_R8G8B8A8, XGL_NUM_FMT_UNORM}, // XGL_FORMAT |
Courtney Goeltzenleuchter | f56fdd4 | 2014-08-20 15:28:00 -0600 | [diff] [blame] | 729 | 0xF // channelWriteMask |
| 730 | } |
| 731 | } |
| 732 | }; |
| 733 | |
| 734 | // TODO: Should take depth buffer format from queried formats |
| 735 | XGL_PIPELINE_DB_STATE_CREATE_INFO db_state = { |
| 736 | XGL_STRUCTURE_TYPE_PIPELINE_DB_STATE_CREATE_INFO, |
| 737 | &cb_state, |
| 738 | {XGL_CH_FMT_R32, XGL_NUM_FMT_DS} // XGL_FORMAT |
| 739 | }; |
| 740 | |
| 741 | info.sType = XGL_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; |
| 742 | info.pNext = &db_state; |
| 743 | info.flags = 0; |
| 744 | err = xglCreateGraphicsPipeline(device(), &info, &pipeline); |
| 745 | ASSERT_XGL_SUCCESS(err); |
| 746 | |
Courtney Goeltzenleuchter | 0246188 | 2014-08-22 16:27:58 -0600 | [diff] [blame] | 747 | err = m_device->AllocAndBindGpuMemory(pipeline, "Pipeline", &m_pipe_mem); |
Courtney Goeltzenleuchter | da91b95 | 2014-08-21 17:34:22 -0600 | [diff] [blame] | 748 | ASSERT_XGL_SUCCESS(err); |
| 749 | |
| 750 | /* |
| 751 | * Shaders are now part of the pipeline, don't need these anymore |
| 752 | */ |
Courtney Goeltzenleuchter | f56fdd4 | 2014-08-20 15:28:00 -0600 | [diff] [blame] | 753 | ASSERT_XGL_SUCCESS(xglDestroyObject(ps)); |
| 754 | ASSERT_XGL_SUCCESS(xglDestroyObject(vs)); |
Courtney Goeltzenleuchter | da91b95 | 2014-08-21 17:34:22 -0600 | [diff] [blame] | 755 | |
Courtney Goeltzenleuchter | 0246188 | 2014-08-22 16:27:58 -0600 | [diff] [blame] | 756 | // typedef struct _XGL_COLOR_ATTACHMENT_VIEW_CREATE_INFO |
| 757 | // { |
| 758 | // XGL_STRUCTURE_TYPE sType; // Must be XGL_STRUCTURE_TYPE_COLOR_ATTACHMENT_VIEW_CREATE_INFO |
| 759 | // XGL_VOID* pNext; // Pointer to next structure |
| 760 | // XGL_IMAGE image; |
| 761 | // XGL_FORMAT format; |
| 762 | // XGL_UINT mipLevel; |
| 763 | // XGL_UINT baseArraySlice; |
| 764 | // XGL_UINT arraySize; |
| 765 | // } XGL_COLOR_ATTACHMENT_VIEW_CREATE_INFO; |
| 766 | XGL_COLOR_ATTACHMENT_VIEW_CREATE_INFO createView = { |
| 767 | XGL_STRUCTURE_TYPE_COLOR_ATTACHMENT_VIEW_CREATE_INFO, |
| 768 | XGL_NULL_HANDLE, |
| 769 | this->m_image, |
Chia-I Wu | 9d77725 | 2014-08-27 15:02:10 +0800 | [diff] [blame] | 770 | {XGL_CH_FMT_R8G8B8A8, XGL_NUM_FMT_UNORM}, |
Courtney Goeltzenleuchter | 0246188 | 2014-08-22 16:27:58 -0600 | [diff] [blame] | 771 | 0, |
| 772 | 0, |
| 773 | 1 |
| 774 | }; |
| 775 | XGL_COLOR_ATTACHMENT_VIEW colorView; |
Courtney Goeltzenleuchter | da91b95 | 2014-08-21 17:34:22 -0600 | [diff] [blame] | 776 | |
Courtney Goeltzenleuchter | 0246188 | 2014-08-22 16:27:58 -0600 | [diff] [blame] | 777 | err = xglCreateColorAttachmentView(device(), &createView, &colorView); |
| 778 | ASSERT_XGL_SUCCESS(err); |
| 779 | |
Chia-I Wu | 57b3fa8 | 2014-08-30 23:58:36 +0800 | [diff] [blame] | 780 | XGL_QUERY_POOL query; |
| 781 | XGL_GPU_MEMORY query_mem; |
| 782 | ASSERT_NO_FATAL_FAILURE(CreateQueryPool(XGL_QUERY_PIPELINE_STATISTICS, 1, &query, &query_mem)); |
| 783 | |
Courtney Goeltzenleuchter | 0246188 | 2014-08-22 16:27:58 -0600 | [diff] [blame] | 784 | // Build command buffer |
| 785 | err = xglBeginCommandBuffer(m_cmdBuffer, 0); |
| 786 | ASSERT_XGL_SUCCESS(err); |
| 787 | |
| 788 | // whatever we want to do, we do it to the whole buffer |
| 789 | XGL_IMAGE_SUBRESOURCE_RANGE srRange = {}; |
| 790 | srRange.aspect = XGL_IMAGE_ASPECT_COLOR; |
| 791 | srRange.baseMipLevel = 0; |
| 792 | srRange.mipLevels = XGL_LAST_MIP_OR_SLICE; |
| 793 | srRange.baseArraySlice = 0; |
| 794 | srRange.arraySize = XGL_LAST_MIP_OR_SLICE; |
| 795 | |
| 796 | // prepare the whole back buffer for clear |
| 797 | XGL_IMAGE_STATE_TRANSITION transitionToClear = {}; |
| 798 | transitionToClear.image = m_image; |
| 799 | transitionToClear.oldState = m_image_state; |
| 800 | transitionToClear.newState = XGL_IMAGE_STATE_CLEAR; |
| 801 | transitionToClear.subresourceRange = srRange; |
| 802 | xglCmdPrepareImages( m_cmdBuffer, 1, &transitionToClear ); |
| 803 | m_image_state = ( XGL_IMAGE_STATE ) transitionToClear.newState; |
| 804 | |
| 805 | // clear the back buffer to dark grey |
| 806 | XGL_UINT clearColor[4] = {64, 64, 64, 0}; |
| 807 | xglCmdClearColorImageRaw( m_cmdBuffer, m_image, clearColor, 1, &srRange ); |
| 808 | |
| 809 | // prepare back buffer for rendering |
| 810 | XGL_IMAGE_STATE_TRANSITION transitionToRender = {}; |
| 811 | transitionToRender.image = m_image; |
| 812 | transitionToRender.oldState = m_image_state; |
| 813 | transitionToRender.newState = XGL_IMAGE_STATE_TARGET_RENDER_ACCESS_OPTIMAL; |
| 814 | transitionToRender.subresourceRange = srRange; |
| 815 | xglCmdPrepareImages( m_cmdBuffer, 1, &transitionToRender ); |
| 816 | m_image_state = ( XGL_IMAGE_STATE ) transitionToRender.newState; |
| 817 | |
| 818 | // bind render target |
| 819 | XGL_COLOR_ATTACHMENT_BIND_INFO colorBind = {}; |
| 820 | colorBind.view = colorView; |
| 821 | colorBind.colorAttachmentState = XGL_IMAGE_STATE_TARGET_RENDER_ACCESS_OPTIMAL; |
| 822 | xglCmdBindAttachments(m_cmdBuffer, 1, &colorBind, NULL ); |
| 823 | |
| 824 | // set all states |
| 825 | xglCmdBindStateObject( m_cmdBuffer, XGL_STATE_BIND_RASTER, m_stateRaster ); |
| 826 | xglCmdBindStateObject( m_cmdBuffer, XGL_STATE_BIND_VIEWPORT, m_stateViewport ); |
Courtney Goeltzenleuchter | 464746c | 2014-08-26 18:16:41 -0600 | [diff] [blame] | 827 | xglCmdBindStateObject( m_cmdBuffer, XGL_STATE_BIND_COLOR_BLEND, m_colorBlend); |
Courtney Goeltzenleuchter | 0246188 | 2014-08-22 16:27:58 -0600 | [diff] [blame] | 828 | xglCmdBindStateObject( m_cmdBuffer, XGL_STATE_BIND_DEPTH_STENCIL, m_stateDepthStencil ); |
| 829 | xglCmdBindStateObject( m_cmdBuffer, XGL_STATE_BIND_MSAA, m_stateMsaa ); |
| 830 | |
| 831 | // bind pipeline, vertex buffer (descriptor set) and WVP (dynamic memory view) |
| 832 | xglCmdBindPipeline( m_cmdBuffer, XGL_PIPELINE_BIND_POINT_GRAPHICS, pipeline ); |
| 833 | // xglCmdBindDescriptorSet(m_cmdBuffer, XGL_PIPELINE_BIND_POINT_GRAPHICS, 0, m_rsrcDescSet, 0 ); |
| 834 | // xglCmdBindDynamicMemoryView( m_cmdBuffer, XGL_PIPELINE_BIND_POINT_GRAPHICS, &m_constantBufferView ); |
| 835 | |
Chia-I Wu | 57b3fa8 | 2014-08-30 23:58:36 +0800 | [diff] [blame] | 836 | xglCmdResetQueryPool(m_cmdBuffer, query, 0, 1); |
| 837 | xglCmdBeginQuery(m_cmdBuffer, query, 0, 0); |
| 838 | |
Courtney Goeltzenleuchter | 0246188 | 2014-08-22 16:27:58 -0600 | [diff] [blame] | 839 | // render the cube |
| 840 | xglCmdDraw( m_cmdBuffer, 0, 3, 0, 1 ); |
| 841 | |
Chia-I Wu | 57b3fa8 | 2014-08-30 23:58:36 +0800 | [diff] [blame] | 842 | xglCmdEndQuery(m_cmdBuffer, query, 0); |
| 843 | |
Courtney Goeltzenleuchter | 0246188 | 2014-08-22 16:27:58 -0600 | [diff] [blame] | 844 | // prepare the back buffer for present |
| 845 | // XGL_IMAGE_STATE_TRANSITION transitionToPresent = {}; |
| 846 | // transitionToPresent.image = m_image; |
| 847 | // transitionToPresent.oldState = m_image_state; |
| 848 | // transitionToPresent.newState = m_display.fullscreen ? XGL_WSI_WIN_PRESENT_SOURCE_FLIP : XGL_WSI_WIN_PRESENT_SOURCE_BLT; |
| 849 | // transitionToPresent.subresourceRange = srRange; |
| 850 | // xglCmdPrepareImages( m_cmdBuffer, 1, &transitionToPresent ); |
| 851 | // m_image_state = ( XGL_IMAGE_STATE ) transitionToPresent.newState; |
| 852 | |
| 853 | // finalize recording of the command buffer |
| 854 | err = xglEndCommandBuffer( m_cmdBuffer ); |
| 855 | ASSERT_XGL_SUCCESS( err ); |
| 856 | |
| 857 | // this command buffer only uses the vertex buffer memory |
| 858 | m_numMemRefs = 0; |
| 859 | // m_memRefs[0].flags = 0; |
| 860 | // m_memRefs[0].mem = m_vtxBufferMemory; |
| 861 | |
| 862 | // submit the command buffer to the universal queue |
| 863 | err = xglQueueSubmit( m_device->m_queue, 1, &m_cmdBuffer, m_numMemRefs, m_memRefs, NULL ); |
| 864 | ASSERT_XGL_SUCCESS( err ); |
| 865 | |
Chia-I Wu | 113e9d9 | 2014-08-27 14:58:05 +0800 | [diff] [blame] | 866 | err = xglQueueWaitIdle( m_device->m_queue ); |
| 867 | ASSERT_XGL_SUCCESS( err ); |
| 868 | |
Courtney Goeltzenleuchter | 464746c | 2014-08-26 18:16:41 -0600 | [diff] [blame] | 869 | // Wait for work to finish before cleaning up. |
| 870 | xglDeviceWaitIdle(m_device->device()); |
| 871 | |
Chia-I Wu | 57b3fa8 | 2014-08-30 23:58:36 +0800 | [diff] [blame] | 872 | XGL_PIPELINE_STATISTICS_DATA stats; |
| 873 | XGL_SIZE stats_size; |
| 874 | err = xglGetQueryPoolResults(query, 0, 1, &stats_size, &stats); |
| 875 | ASSERT_XGL_SUCCESS( err ); |
| 876 | ASSERT_EQ(stats_size, sizeof(stats)); |
| 877 | |
| 878 | ASSERT_EQ(stats.vsInvocations, 3); |
| 879 | ASSERT_EQ(stats.cPrimitives, 1); |
| 880 | ASSERT_EQ(stats.cInvocations, 1); |
| 881 | |
| 882 | DestroyQueryPool(query, query_mem); |
| 883 | |
Chia-I Wu | 113e9d9 | 2014-08-27 14:58:05 +0800 | [diff] [blame] | 884 | WritePPM( "TriangleTest.ppm", width, height ); |
Courtney Goeltzenleuchter | f21d32d | 2014-09-01 13:57:15 -0600 | [diff] [blame] | 885 | m_screen.Display(m_image, m_image_mem); |
Chia-I Wu | 113e9d9 | 2014-08-27 14:58:05 +0800 | [diff] [blame] | 886 | |
Courtney Goeltzenleuchter | 0246188 | 2014-08-22 16:27:58 -0600 | [diff] [blame] | 887 | ASSERT_XGL_SUCCESS(xglDestroyObject(pipeline)); |
Courtney Goeltzenleuchter | 464746c | 2014-08-26 18:16:41 -0600 | [diff] [blame] | 888 | ASSERT_XGL_SUCCESS(xglDestroyObject(m_cmdBuffer)); |
| 889 | ASSERT_XGL_SUCCESS(xglDestroyObject(m_stateRaster)); |
| 890 | ASSERT_XGL_SUCCESS(xglDestroyObject(m_stateViewport)); |
| 891 | ASSERT_XGL_SUCCESS(xglDestroyObject(m_stateDepthStencil)); |
| 892 | ASSERT_XGL_SUCCESS(xglDestroyObject(m_stateMsaa)); |
| 893 | DestroyImage(); |
| 894 | // DestroyImageView(); |
Courtney Goeltzenleuchter | 0246188 | 2014-08-22 16:27:58 -0600 | [diff] [blame] | 895 | } |
| 896 | |
Chia-I Wu | 113e9d9 | 2014-08-27 14:58:05 +0800 | [diff] [blame] | 897 | void XglRenderTest::WritePPM( const char *filename, int width, int height ) |
| 898 | { |
| 899 | XGL_RESULT err; |
| 900 | int x, y; |
| 901 | |
| 902 | const XGL_IMAGE_SUBRESOURCE sr = { |
| 903 | XGL_IMAGE_ASPECT_COLOR, 0, 0 |
| 904 | }; |
| 905 | XGL_SUBRESOURCE_LAYOUT sr_layout; |
| 906 | XGL_UINT data_size; |
| 907 | |
| 908 | err = xglGetImageSubresourceInfo( m_image, &sr, XGL_INFO_TYPE_SUBRESOURCE_LAYOUT, &data_size, &sr_layout); |
| 909 | ASSERT_XGL_SUCCESS( err ); |
| 910 | ASSERT_EQ(data_size, sizeof(sr_layout)); |
| 911 | |
| 912 | const char *ptr; |
| 913 | |
| 914 | err = xglMapMemory( m_image_mem, 0, (XGL_VOID **) &ptr ); |
| 915 | ASSERT_XGL_SUCCESS( err ); |
| 916 | |
| 917 | ptr += sr_layout.offset; |
| 918 | |
| 919 | ofstream file (filename); |
| 920 | ASSERT_TRUE(file.is_open()) << "Unable to open file: " << filename; |
| 921 | |
| 922 | file << "P6\n"; |
| 923 | file << width << "\n"; |
| 924 | file << height << "\n"; |
| 925 | file << 255 << "\n"; |
| 926 | |
| 927 | for (y = 0; y < height; y++) { |
| 928 | const char *row = ptr; |
| 929 | |
| 930 | for (x = 0; x < width; x++) { |
| 931 | file.write(row, 3); |
| 932 | row += 4; |
| 933 | } |
| 934 | |
| 935 | ptr += sr_layout.rowPitch; |
| 936 | } |
| 937 | |
| 938 | file.close(); |
| 939 | |
| 940 | err = xglUnmapMemory( m_image_mem ); |
| 941 | ASSERT_XGL_SUCCESS( err ); |
| 942 | } |
| 943 | |
Courtney Goeltzenleuchter | 0246188 | 2014-08-22 16:27:58 -0600 | [diff] [blame] | 944 | TEST_F(XglRenderTest, TestDrawTriangle) { |
| 945 | DrawTriangleTest(); |
Courtney Goeltzenleuchter | cc5eb3a | 2014-08-19 18:35:50 -0600 | [diff] [blame] | 946 | } |
| 947 | |
| 948 | int main(int argc, char **argv) { |
Courtney Goeltzenleuchter | f21d32d | 2014-09-01 13:57:15 -0600 | [diff] [blame] | 949 | // glutInit(argc, argv); |
Courtney Goeltzenleuchter | cc5eb3a | 2014-08-19 18:35:50 -0600 | [diff] [blame] | 950 | ::testing::InitGoogleTest(&argc, argv); |
Courtney Goeltzenleuchter | f21d32d | 2014-09-01 13:57:15 -0600 | [diff] [blame] | 951 | glutInit(&argc, argv); |
Courtney Goeltzenleuchter | cc5eb3a | 2014-08-19 18:35:50 -0600 | [diff] [blame] | 952 | return RUN_ALL_TESTS(); |
| 953 | } |