Courtney Goeltzenleuchter | b85c581 | 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 | 76a643b | 2014-08-21 17:34:22 -0600 | [diff] [blame] | 60 | #include <iostream> |
| 61 | #include <fstream> |
| 62 | using namespace std; |
Courtney Goeltzenleuchter | b85c581 | 2014-08-19 18:35:50 -0600 | [diff] [blame] | 63 | |
| 64 | #include <xgl.h> |
Courtney Goeltzenleuchter | ff87c82 | 2014-10-03 18:05:10 -0600 | [diff] [blame] | 65 | #include <xglIntelExt.h> |
Courtney Goeltzenleuchter | b85c581 | 2014-08-19 18:35:50 -0600 | [diff] [blame] | 66 | #include "gtest-1.7.0/include/gtest/gtest.h" |
| 67 | |
| 68 | #include "xgldevice.h" |
Courtney Goeltzenleuchter | 04814f8 | 2014-09-01 16:37:18 -0600 | [diff] [blame] | 69 | #include "xglimage.h" |
Chia-I Wu | 4115c89 | 2014-08-28 11:56:29 +0800 | [diff] [blame] | 70 | #include "icd-bil.h" |
Courtney Goeltzenleuchter | b85c581 | 2014-08-19 18:35:50 -0600 | [diff] [blame] | 71 | |
Courtney Goeltzenleuchter | cb5a89c | 2014-10-08 12:20:26 -0600 | [diff] [blame^] | 72 | #include "xglrenderframework.h" |
Courtney Goeltzenleuchter | 2268d1e | 2014-09-01 13:57:15 -0600 | [diff] [blame] | 73 | |
Courtney Goeltzenleuchter | a948d84 | 2014-08-22 16:27:58 -0600 | [diff] [blame] | 74 | //-------------------------------------------------------------------------------------- |
| 75 | // Mesh and VertexFormat Data |
| 76 | //-------------------------------------------------------------------------------------- |
| 77 | struct Vertex |
| 78 | { |
| 79 | XGL_FLOAT posX, posY, posZ, posW; // Position data |
| 80 | XGL_FLOAT r, g, b, a; // Color |
| 81 | }; |
| 82 | |
| 83 | #define XYZ1(_x_, _y_, _z_) (_x_), (_y_), (_z_), 1.f |
| 84 | |
| 85 | static const Vertex g_vbData[] = |
| 86 | { |
| 87 | { XYZ1( -1, -1, -1 ), XYZ1( 0.f, 0.f, 0.f ) }, |
| 88 | { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) }, |
| 89 | { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) }, |
| 90 | { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) }, |
| 91 | { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) }, |
| 92 | { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) }, |
| 93 | |
| 94 | { XYZ1( -1, -1, 1 ), XYZ1( 0.f, 0.f, 1.f ) }, |
| 95 | { XYZ1( -1, 1, 1 ), XYZ1( 0.f, 1.f, 1.f ) }, |
| 96 | { XYZ1( 1, -1, 1 ), XYZ1( 1.f, 0.f, 1.f ) }, |
| 97 | { XYZ1( 1, -1, 1 ), XYZ1( 1.f, 0.f, 1.f ) }, |
| 98 | { XYZ1( -1, 1, 1 ), XYZ1( 0.f, 1.f, 1.f ) }, |
| 99 | { XYZ1( 1, 1, 1 ), XYZ1( 1.f, 1.f, 1.f ) }, |
| 100 | |
| 101 | { XYZ1( 1, 1, 1 ), XYZ1( 1.f, 1.f, 1.f ) }, |
| 102 | { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) }, |
| 103 | { XYZ1( 1, -1, 1 ), XYZ1( 1.f, 0.f, 1.f ) }, |
| 104 | { XYZ1( 1, -1, 1 ), XYZ1( 1.f, 0.f, 1.f ) }, |
| 105 | { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) }, |
| 106 | { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) }, |
| 107 | |
| 108 | { XYZ1( -1, 1, 1 ), XYZ1( 0.f, 1.f, 1.f ) }, |
| 109 | { XYZ1( -1, -1, 1 ), XYZ1( 0.f, 0.f, 1.f ) }, |
| 110 | { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) }, |
| 111 | { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) }, |
| 112 | { XYZ1( -1, -1, 1 ), XYZ1( 0.f, 0.f, 1.f ) }, |
| 113 | { XYZ1( -1, -1, -1 ), XYZ1( 0.f, 0.f, 0.f ) }, |
| 114 | |
| 115 | { XYZ1( 1, 1, 1 ), XYZ1( 1.f, 1.f, 1.f ) }, |
| 116 | { XYZ1( -1, 1, 1 ), XYZ1( 0.f, 1.f, 1.f ) }, |
| 117 | { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) }, |
| 118 | { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) }, |
| 119 | { XYZ1( -1, 1, 1 ), XYZ1( 0.f, 1.f, 1.f ) }, |
| 120 | { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) }, |
| 121 | |
| 122 | { XYZ1( 1, -1, 1 ), XYZ1( 1.f, 0.f, 1.f ) }, |
| 123 | { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) }, |
| 124 | { XYZ1( -1, -1, 1 ), XYZ1( 0.f, 0.f, 1.f ) }, |
| 125 | { XYZ1( -1, -1, 1 ), XYZ1( 0.f, 0.f, 1.f ) }, |
| 126 | { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) }, |
| 127 | { XYZ1( -1, -1, -1 ), XYZ1( 0.f, 0.f, 0.f ) }, |
| 128 | }; |
| 129 | |
Chia-I Wu | 6e9789c | 2014-08-30 14:03:32 +0800 | [diff] [blame] | 130 | static const uint32_t gen6_fs[] = { |
| 131 | 0x00600001, 0x202003fe, 0x00000000, 0x3f800000, // mov(8) m1<1>F 1F { align1 1Q }; |
| 132 | 0x00600001, 0x204003fe, 0x00000000, 0x00000000, // mov(8) m2<1>F 0F { align1 1Q }; |
| 133 | 0x00600001, 0x206003fe, 0x00000000, 0x00000000, // mov(8) m3<1>F 0F { align1 1Q }; |
| 134 | 0x00600001, 0x208003fe, 0x00000000, 0x3f800000, // mov(8) m4<1>F 1F { align1 1Q }; |
| 135 | 0x05600032, 0x20001fc8, 0x008d0020, 0x88019400, // sendc(8) null m1<8,8,1>F |
| 136 | // render RT write SIMD8 LastRT Surface = 0 mlen 4 rlen 0 { align1 1Q EOT }; |
| 137 | }; |
| 138 | |
| 139 | static const uint32_t gen6_vs[] = { |
| 140 | 0x01600110, 0x200f1ca4, 0x00600020, 0x00000000, // cmp.z.f0(8) null g1<4,4,1>.xD 0D { align16 1Q }; |
| 141 | 0x00670122, 0x000a108f, 0x000e0004, 0x000e0004, // (+f0.all4h) if(8) JIP: 10 { align16 1Q }; |
| 142 | 0x00600501, 0x204303fd, 0x00000000, 0xbf800000, // mov(8) g2<1>.xyF -1F { align16 NoDDClr 1Q }; |
| 143 | 0x00600d01, 0x204403fd, 0x00000000, 0x00000000, // mov(8) g2<1>.zF 0F { align16 NoDDClr,NoDDChk 1Q }; |
| 144 | 0x00600901, 0x204803fd, 0x00000000, 0x3f800000, // mov(8) g2<1>.wF 1F { align16 NoDDChk 1Q }; |
| 145 | 0x00600124, 0x0014108f, 0x006e0004, 0x006e0004, // else(8) JIP: 20 { align16 1Q }; |
| 146 | 0x01600110, 0x200f1ca4, 0x00600020, 0x00000001, // cmp.z.f0(8) null g1<4,4,1>.xD 1D { align16 1Q }; |
| 147 | 0x00670122, 0x000a108f, 0x000e0004, 0x000e0004, // (+f0.all4h) if(8) JIP: 10 { align16 1Q }; |
| 148 | 0x00600501, 0x204903fd, 0x00000000, 0x3f800000, // mov(8) g2<1>.xwF 1F { align16 NoDDClr 1Q }; |
| 149 | 0x00600d01, 0x204203fd, 0x00000000, 0xbf800000, // mov(8) g2<1>.yF -1F { align16 NoDDClr,NoDDChk 1Q }; |
| 150 | 0x00600901, 0x204403fd, 0x00000000, 0x00000000, // mov(8) g2<1>.zF 0F { align16 NoDDChk 1Q }; |
| 151 | 0x00600124, 0x0006108f, 0x006e0004, 0x006e0004, // else(8) JIP: 6 { align16 1Q }; |
| 152 | 0x00600501, 0x204503fd, 0x00000000, 0x00000000, // mov(8) g2<1>.xzF 0F { align16 NoDDClr 1Q }; |
| 153 | 0x00600901, 0x204a03fd, 0x00000000, 0x3f800000, // mov(8) g2<1>.ywF 1F { align16 NoDDChk 1Q }; |
| 154 | 0x00600125, 0x0002108f, 0x006e0004, 0x006e0002, // endif(8) JIP: 2 { align16 1Q }; |
| 155 | 0x00600125, 0x0002108f, 0x006e0004, 0x006e0002, // endif(8) JIP: 2 { align16 1Q }; |
| 156 | 0x00600101, 0x204f0062, 0x00000000, 0x00000000, // mov(8) m2<1>UD 0x00000000UD { align16 1Q }; |
| 157 | 0x00600101, 0x206f03be, 0x006e0044, 0x00000000, // mov(8) m3<1>F g2<4,4,1>F { align16 1Q }; |
| 158 | 0x00600301, 0x202f0022, 0x006e0004, 0x00000000, // mov(8) m1<1>UD g0<4,4,1>UD { align16 WE_all 1Q }; |
| 159 | 0x06600131, 0x200f1fdc, 0x006e0024, 0x8608c400, // send(8) null m1<4,4,1>F |
| 160 | // urb 0 urb_write interleave used complete mlen 3 rlen 0 { align16 1Q EOT }; |
| 161 | }; |
| 162 | |
| 163 | static const uint32_t gen7_fs[] = { |
| 164 | 0x00600001, 0x2e2003fd, 0x00000000, 0x3f800000, // mov(8) g113<1>F 1F { align1 1Q }; |
| 165 | 0x00600001, 0x2e4003fd, 0x00000000, 0x00000000, // mov(8) g114<1>F 0F { align1 1Q }; |
| 166 | 0x00600001, 0x2e6003fd, 0x00000000, 0x00000000, // mov(8) g115<1>F 0F { align1 1Q }; |
| 167 | 0x00600001, 0x2e8003fd, 0x00000000, 0x3f800000, // mov(8) g116<1>F 1F { align1 1Q }; |
| 168 | 0x05600032, 0x20001fa8, 0x008d0e20, 0x88031400, // sendc(8) null g113<8,8,1>F |
| 169 | // render RT write SIMD8 LastRT Surface = 0 mlen 4 rlen 0 { align1 1Q EOT }; |
| 170 | }; |
| 171 | |
| 172 | static const uint32_t gen7_vs[] = { |
| 173 | 0x01608110, 0x200f1ca4, 0x00600020, 0x00000000, // cmp.z.f0(8) null g1<4,4,1>.xD 0D { align16 1Q switch }; |
| 174 | 0x00670122, 0x200f0c84, 0x000e0004, 0x001c000a, // (+f0.all4h) if(8) JIP: 10 UIP: 28 { align16 1Q }; |
| 175 | 0x00600501, 0x204303fd, 0x00000000, 0xbf800000, // mov(8) g2<1>.xyF -1F { align16 NoDDClr 1Q }; |
| 176 | 0x00600d01, 0x204403fd, 0x00000000, 0x00000000, // mov(8) g2<1>.zF 0F { align16 NoDDClr,NoDDChk 1Q }; |
| 177 | 0x00600901, 0x204803fd, 0x00000000, 0x3f800000, // mov(8) g2<1>.wF 1F { align16 NoDDChk 1Q }; |
| 178 | 0x00600124, 0x200f0c84, 0x006e0004, 0x00000014, // else(8) JIP: 20 { align16 1Q }; |
| 179 | 0x01608110, 0x200f1ca4, 0x00600020, 0x00000001, // cmp.z.f0(8) null g1<4,4,1>.xD 1D { align16 1Q switch }; |
| 180 | 0x00670122, 0x200f0c84, 0x000e0004, 0x000e000a, // (+f0.all4h) if(8) JIP: 10 UIP: 14 { align16 1Q }; |
| 181 | 0x00600501, 0x204903fd, 0x00000000, 0x3f800000, // mov(8) g2<1>.xwF 1F { align16 NoDDClr 1Q }; |
| 182 | 0x00600d01, 0x204203fd, 0x00000000, 0xbf800000, // mov(8) g2<1>.yF -1F { align16 NoDDClr,NoDDChk 1Q }; |
| 183 | 0x00600901, 0x204403fd, 0x00000000, 0x00000000, // mov(8) g2<1>.zF 0F { align16 NoDDChk 1Q }; |
| 184 | 0x00600124, 0x200f0c84, 0x006e0004, 0x00000006, // else(8) JIP: 6 { align16 1Q }; |
| 185 | 0x00600501, 0x204503fd, 0x00000000, 0x00000000, // mov(8) g2<1>.xzF 0F { align16 NoDDClr 1Q }; |
| 186 | 0x00600901, 0x204a03fd, 0x00000000, 0x3f800000, // mov(8) g2<1>.ywF 1F { align16 NoDDChk 1Q }; |
| 187 | 0x00600125, 0x200f0c84, 0x006e0004, 0x00000002, // endif(8) JIP: 2 { align16 1Q }; |
| 188 | 0x00600125, 0x200f0c84, 0x006e0004, 0x00000002, // endif(8) JIP: 2 { align16 1Q }; |
| 189 | 0x00600101, 0x2e4f0061, 0x00000000, 0x00000000, // mov(8) g114<1>UD 0x00000000UD { align16 1Q }; |
| 190 | 0x00600101, 0x2e6f03bd, 0x006e0044, 0x00000000, // mov(8) g115<1>F g2<4,4,1>F { align16 1Q }; |
| 191 | 0x00600301, 0x2e2f0021, 0x006e0004, 0x00000000, // mov(8) g113<1>UD g0<4,4,1>UD { align16 WE_all 1Q }; |
| 192 | 0x00000206, 0x2e340c21, 0x00000014, 0x0000ff00, // or(1) g113.5<1>UD g0.5<0,1,0>UD 0x0000ff00UD { align1 WE_all }; |
| 193 | 0x06600131, 0x200f1fbc, 0x006e0e24, 0x8608c000, // send(8) null g113<4,4,1>F |
| 194 | // urb 0 write HWord interleave complete mlen 3 rlen 0 { align16 1Q EOT }; |
| 195 | }; |
Courtney Goeltzenleuchter | a948d84 | 2014-08-22 16:27:58 -0600 | [diff] [blame] | 196 | |
Courtney Goeltzenleuchter | cb5a89c | 2014-10-08 12:20:26 -0600 | [diff] [blame^] | 197 | class XglRenderTest : public XglRenderFramework |
Courtney Goeltzenleuchter | 2802979 | 2014-09-04 16:26:02 -0600 | [diff] [blame] | 198 | { |
Courtney Goeltzenleuchter | b85c581 | 2014-08-19 18:35:50 -0600 | [diff] [blame] | 199 | public: |
Courtney Goeltzenleuchter | a948d84 | 2014-08-22 16:27:58 -0600 | [diff] [blame] | 200 | void InitMesh( XGL_UINT32 numVertices, XGL_GPU_SIZE vbStride, const void* vertices ); |
Cody Northrop | 350727b | 2014-10-06 15:42:00 -0600 | [diff] [blame] | 201 | void InitTexture(); |
| 202 | void InitSampler(); |
Courtney Goeltzenleuchter | a948d84 | 2014-08-22 16:27:58 -0600 | [diff] [blame] | 203 | void DrawTriangleTest(); |
Tobin Ehlis | 34e0e44 | 2014-10-07 14:41:29 -0600 | [diff] [blame] | 204 | void DrawRotatedTriangleTest(); |
Courtney Goeltzenleuchter | cb5a89c | 2014-10-08 12:20:26 -0600 | [diff] [blame^] | 205 | void NewGenerateClearAndPrepareBufferCmds(XglImage *renderTarget); |
| 206 | void NewGenerateBindStateAndPipelineCmds(XGL_PIPELINE* pipeline); |
| 207 | |
Courtney Goeltzenleuchter | b85c581 | 2014-08-19 18:35:50 -0600 | [diff] [blame] | 208 | |
| 209 | protected: |
Cody Northrop | 350727b | 2014-10-06 15:42:00 -0600 | [diff] [blame] | 210 | XGL_IMAGE m_texture; |
| 211 | XGL_IMAGE_VIEW m_textureView; |
| 212 | XGL_IMAGE_VIEW_ATTACH_INFO m_textureViewInfo; |
| 213 | XGL_GPU_MEMORY m_textureMem; |
| 214 | |
| 215 | XGL_SAMPLER m_sampler; |
| 216 | |
Courtney Goeltzenleuchter | cb5a89c | 2014-10-08 12:20:26 -0600 | [diff] [blame^] | 217 | // XGL_APPLICATION_INFO app_info; |
| 218 | // XGL_PHYSICAL_GPU objs[MAX_GPUS]; |
| 219 | // XGL_UINT gpu_count; |
| 220 | // XGL_GPU_MEMORY m_descriptor_set_mem; |
| 221 | // XGL_GPU_MEMORY m_pipe_mem; |
| 222 | // XglDevice *m_device; |
| 223 | // XGL_CMD_BUFFER m_cmdBuffer; |
| 224 | // XGL_UINT32 m_numVertices; |
| 225 | // XGL_MEMORY_VIEW_ATTACH_INFO m_vtxBufferView; |
| 226 | // XGL_MEMORY_VIEW_ATTACH_INFO m_constantBufferView; |
| 227 | // XGL_GPU_MEMORY m_vtxBufferMem; |
| 228 | // XGL_GPU_MEMORY m_constantBufferMem; |
| 229 | // XGL_UINT32 m_numMemRefs; |
| 230 | // XGL_MEMORY_REF m_memRefs[5]; |
| 231 | // XGL_RASTER_STATE_OBJECT m_stateRaster; |
| 232 | // XGL_COLOR_BLEND_STATE_OBJECT m_colorBlend; |
| 233 | // XGL_VIEWPORT_STATE_OBJECT m_stateViewport; |
| 234 | // XGL_DEPTH_STENCIL_STATE_OBJECT m_stateDepthStencil; |
| 235 | // XGL_MSAA_STATE_OBJECT m_stateMsaa; |
| 236 | // XGL_DESCRIPTOR_SET m_rsrcDescSet; |
Courtney Goeltzenleuchter | b85c581 | 2014-08-19 18:35:50 -0600 | [diff] [blame] | 237 | |
| 238 | virtual void SetUp() { |
Courtney Goeltzenleuchter | b85c581 | 2014-08-19 18:35:50 -0600 | [diff] [blame] | 239 | |
| 240 | this->app_info.sType = XGL_STRUCTURE_TYPE_APPLICATION_INFO; |
| 241 | this->app_info.pNext = NULL; |
| 242 | this->app_info.pAppName = (const XGL_CHAR *) "base"; |
| 243 | this->app_info.appVersion = 1; |
| 244 | this->app_info.pEngineName = (const XGL_CHAR *) "unittest"; |
| 245 | this->app_info.engineVersion = 1; |
| 246 | this->app_info.apiVersion = XGL_MAKE_VERSION(0, 22, 0); |
| 247 | |
Cody Northrop | 350727b | 2014-10-06 15:42:00 -0600 | [diff] [blame] | 248 | memset(&m_textureViewInfo, 0, sizeof(m_textureViewInfo)); |
| 249 | m_textureViewInfo.sType = XGL_STRUCTURE_TYPE_IMAGE_VIEW_ATTACH_INFO; |
| 250 | |
Courtney Goeltzenleuchter | cb5a89c | 2014-10-08 12:20:26 -0600 | [diff] [blame^] | 251 | InitFramework(); |
Courtney Goeltzenleuchter | b85c581 | 2014-08-19 18:35:50 -0600 | [diff] [blame] | 252 | } |
| 253 | |
| 254 | virtual void TearDown() { |
Courtney Goeltzenleuchter | cb5a89c | 2014-10-08 12:20:26 -0600 | [diff] [blame^] | 255 | // Clean up resources before we reset |
| 256 | ShutdownFramework(); |
Courtney Goeltzenleuchter | b85c581 | 2014-08-19 18:35:50 -0600 | [diff] [blame] | 257 | } |
| 258 | }; |
| 259 | |
Courtney Goeltzenleuchter | a948d84 | 2014-08-22 16:27:58 -0600 | [diff] [blame] | 260 | // this function will create the vertex buffer and fill it with the mesh data |
| 261 | void XglRenderTest::InitMesh( XGL_UINT32 numVertices, XGL_GPU_SIZE vbStride, |
| 262 | const void* vertices ) |
| 263 | { |
| 264 | XGL_RESULT err = XGL_SUCCESS; |
| 265 | |
| 266 | assert( numVertices * vbStride > 0 ); |
| 267 | m_numVertices = numVertices; |
| 268 | |
| 269 | XGL_MEMORY_ALLOC_INFO alloc_info = {}; |
| 270 | XGL_UINT8 *pData; |
| 271 | |
| 272 | alloc_info.sType = XGL_STRUCTURE_TYPE_MEMORY_ALLOC_INFO; |
| 273 | alloc_info.allocationSize = numVertices * vbStride; |
| 274 | alloc_info.alignment = 0; |
| 275 | alloc_info.heapCount = 1; |
| 276 | alloc_info.heaps[0] = 0; // TODO: Use known existing heap |
| 277 | |
| 278 | alloc_info.flags = XGL_MEMORY_HEAP_CPU_VISIBLE_BIT; |
| 279 | alloc_info.memPriority = XGL_MEMORY_PRIORITY_NORMAL; |
| 280 | |
| 281 | err = xglAllocMemory(device(), &alloc_info, &m_vtxBufferMem); |
| 282 | ASSERT_XGL_SUCCESS(err); |
| 283 | |
| 284 | err = xglMapMemory(m_vtxBufferMem, 0, (XGL_VOID **) &pData); |
| 285 | ASSERT_XGL_SUCCESS(err); |
| 286 | |
| 287 | memcpy(pData, vertices, alloc_info.allocationSize); |
| 288 | |
| 289 | err = xglUnmapMemory(m_vtxBufferMem); |
| 290 | ASSERT_XGL_SUCCESS(err); |
| 291 | |
| 292 | // set up the memory view for the vertex buffer |
| 293 | this->m_vtxBufferView.stride = vbStride; |
| 294 | this->m_vtxBufferView.range = numVertices * vbStride; |
| 295 | this->m_vtxBufferView.offset = 0; |
| 296 | this->m_vtxBufferView.mem = m_vtxBufferMem; |
| 297 | this->m_vtxBufferView.format.channelFormat = XGL_CH_FMT_UNDEFINED; |
| 298 | this->m_vtxBufferView.format.numericFormat = XGL_NUM_FMT_UNDEFINED; |
| 299 | |
| 300 | // open the command buffer |
| 301 | err = xglBeginCommandBuffer( m_cmdBuffer, 0 ); |
| 302 | ASSERT_XGL_SUCCESS(err); |
| 303 | |
| 304 | XGL_MEMORY_STATE_TRANSITION transition = {}; |
| 305 | transition.mem = m_vtxBufferMem; |
| 306 | transition.oldState = XGL_MEMORY_STATE_DATA_TRANSFER; |
| 307 | transition.newState = XGL_MEMORY_STATE_GRAPHICS_SHADER_READ_ONLY; |
| 308 | transition.offset = 0; |
| 309 | transition.regionSize = numVertices * vbStride; |
| 310 | |
| 311 | // write transition to the command buffer |
| 312 | xglCmdPrepareMemoryRegions( m_cmdBuffer, 1, &transition ); |
| 313 | this->m_vtxBufferView.state = XGL_MEMORY_STATE_GRAPHICS_SHADER_READ_ONLY; |
| 314 | |
| 315 | // finish recording the command buffer |
| 316 | err = xglEndCommandBuffer( m_cmdBuffer ); |
| 317 | ASSERT_XGL_SUCCESS(err); |
| 318 | |
| 319 | // this command buffer only uses the vertex buffer memory |
| 320 | m_numMemRefs = 1; |
| 321 | m_memRefs[0].flags = 0; |
| 322 | m_memRefs[0].mem = m_vtxBufferMem; |
| 323 | |
| 324 | // submit the command buffer to the universal queue |
| 325 | err = xglQueueSubmit( m_device->m_queue, 1, &m_cmdBuffer, m_numMemRefs, m_memRefs, NULL ); |
| 326 | ASSERT_XGL_SUCCESS(err); |
| 327 | } |
| 328 | |
Cody Northrop | 350727b | 2014-10-06 15:42:00 -0600 | [diff] [blame] | 329 | void XglRenderTest::InitTexture() |
| 330 | { |
Cody Northrop | 904742c | 2014-10-07 16:25:00 -0600 | [diff] [blame] | 331 | #define DEMO_TEXTURE_COUNT 1 |
| 332 | |
| 333 | const XGL_FORMAT tex_format = { XGL_CH_FMT_B8G8R8A8, XGL_NUM_FMT_UNORM }; |
| 334 | const XGL_INT tex_width = 16; |
| 335 | const XGL_INT tex_height = 16; |
| 336 | const uint32_t tex_colors[DEMO_TEXTURE_COUNT][2] = { |
| 337 | { 0xffff0000, 0xff00ff00 }, |
| 338 | }; |
Cody Northrop | 350727b | 2014-10-06 15:42:00 -0600 | [diff] [blame] | 339 | XGL_RESULT err; |
Cody Northrop | 904742c | 2014-10-07 16:25:00 -0600 | [diff] [blame] | 340 | XGL_UINT i; |
Cody Northrop | 350727b | 2014-10-06 15:42:00 -0600 | [diff] [blame] | 341 | |
Cody Northrop | 904742c | 2014-10-07 16:25:00 -0600 | [diff] [blame] | 342 | for (i = 0; i < DEMO_TEXTURE_COUNT; i++) { |
| 343 | const XGL_SAMPLER_CREATE_INFO sampler = { |
| 344 | .sType = XGL_STRUCTURE_TYPE_SAMPLER_CREATE_INFO, |
| 345 | .pNext = NULL, |
| 346 | .magFilter = XGL_TEX_FILTER_NEAREST, |
| 347 | .minFilter = XGL_TEX_FILTER_NEAREST, |
| 348 | .mipMode = XGL_TEX_MIPMAP_BASE, |
| 349 | .addressU = XGL_TEX_ADDRESS_WRAP, |
| 350 | .addressV = XGL_TEX_ADDRESS_WRAP, |
| 351 | .addressW = XGL_TEX_ADDRESS_WRAP, |
| 352 | .mipLodBias = 0.0f, |
| 353 | .maxAnisotropy = 0, |
| 354 | .compareFunc = XGL_COMPARE_NEVER, |
| 355 | .minLod = 0.0f, |
| 356 | .maxLod = 0.0f, |
| 357 | .borderColorType = XGL_BORDER_COLOR_OPAQUE_WHITE, |
| 358 | }; |
| 359 | const XGL_IMAGE_CREATE_INFO image = { |
| 360 | .sType = XGL_STRUCTURE_TYPE_IMAGE_CREATE_INFO, |
| 361 | .pNext = NULL, |
| 362 | .imageType = XGL_IMAGE_2D, |
| 363 | .format = tex_format, |
| 364 | .extent = { tex_width, tex_height, 1 }, |
| 365 | .mipLevels = 1, |
| 366 | .arraySize = 1, |
| 367 | .samples = 1, |
| 368 | .tiling = XGL_LINEAR_TILING, |
| 369 | .usage = XGL_IMAGE_USAGE_SHADER_ACCESS_READ_BIT, |
| 370 | .flags = 0, |
| 371 | }; |
| 372 | XGL_MEMORY_ALLOC_INFO mem_alloc; |
| 373 | mem_alloc.sType = XGL_STRUCTURE_TYPE_MEMORY_ALLOC_INFO; |
| 374 | mem_alloc.pNext = NULL; |
| 375 | mem_alloc.allocationSize = 0; |
| 376 | mem_alloc.alignment = 0; |
| 377 | mem_alloc.flags = 0; |
| 378 | mem_alloc.heapCount = 0; |
| 379 | mem_alloc.memPriority = XGL_MEMORY_PRIORITY_NORMAL; |
| 380 | XGL_IMAGE_VIEW_CREATE_INFO view; |
| 381 | view.sType = XGL_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; |
| 382 | view.pNext = NULL; |
| 383 | view.image = XGL_NULL_HANDLE; |
| 384 | view.viewType = XGL_IMAGE_VIEW_2D; |
| 385 | view.format = image.format; |
| 386 | view.channels.r = XGL_CHANNEL_SWIZZLE_R; |
| 387 | view.channels.g = XGL_CHANNEL_SWIZZLE_G; |
| 388 | view.channels.b = XGL_CHANNEL_SWIZZLE_B; |
| 389 | view.channels.a = XGL_CHANNEL_SWIZZLE_A; |
| 390 | view.subresourceRange.aspect = XGL_IMAGE_ASPECT_COLOR; |
| 391 | view.subresourceRange.baseMipLevel = 0; |
| 392 | view.subresourceRange.mipLevels = 1; |
| 393 | view.subresourceRange.baseArraySlice = 0; |
| 394 | view.subresourceRange.arraySize = 1; |
| 395 | view.minLod = 0.0f; |
Cody Northrop | 350727b | 2014-10-06 15:42:00 -0600 | [diff] [blame] | 396 | |
Cody Northrop | 904742c | 2014-10-07 16:25:00 -0600 | [diff] [blame] | 397 | XGL_MEMORY_REQUIREMENTS mem_reqs; |
| 398 | XGL_SIZE mem_reqs_size; |
Cody Northrop | 350727b | 2014-10-06 15:42:00 -0600 | [diff] [blame] | 399 | |
Cody Northrop | 904742c | 2014-10-07 16:25:00 -0600 | [diff] [blame] | 400 | /* create sampler */ |
| 401 | err = xglCreateSampler(device(), &sampler, &m_sampler); |
| 402 | assert(!err); |
| 403 | |
| 404 | /* create image */ |
| 405 | err = xglCreateImage(device(), &image, &m_texture); |
| 406 | assert(!err); |
| 407 | |
| 408 | err = xglGetObjectInfo(m_texture, |
| 409 | XGL_INFO_TYPE_MEMORY_REQUIREMENTS, |
| 410 | &mem_reqs_size, &mem_reqs); |
| 411 | assert(!err && mem_reqs_size == sizeof(mem_reqs)); |
| 412 | |
| 413 | mem_alloc.allocationSize = mem_reqs.size; |
| 414 | mem_alloc.alignment = mem_reqs.alignment; |
| 415 | mem_alloc.heapCount = mem_reqs.heapCount; |
| 416 | memcpy(mem_alloc.heaps, mem_reqs.heaps, |
| 417 | sizeof(mem_reqs.heaps[0]) * mem_reqs.heapCount); |
| 418 | |
| 419 | /* allocate memory */ |
| 420 | err = xglAllocMemory(device(), &mem_alloc, &m_textureMem); |
| 421 | assert(!err); |
| 422 | |
| 423 | /* bind memory */ |
| 424 | err = xglBindObjectMemory(m_texture, m_textureMem, 0); |
| 425 | assert(!err); |
| 426 | |
| 427 | /* create image view */ |
| 428 | view.image = m_texture; |
| 429 | err = xglCreateImageView(device(), &view, &m_textureView); |
| 430 | assert(!err); |
Cody Northrop | 350727b | 2014-10-06 15:42:00 -0600 | [diff] [blame] | 431 | } |
| 432 | |
Cody Northrop | 904742c | 2014-10-07 16:25:00 -0600 | [diff] [blame] | 433 | for (i = 0; i < DEMO_TEXTURE_COUNT; i++) { |
| 434 | const XGL_IMAGE_SUBRESOURCE subres = { |
| 435 | .aspect = XGL_IMAGE_ASPECT_COLOR, |
| 436 | .mipLevel = 0, |
| 437 | .arraySlice = 0, |
| 438 | }; |
| 439 | XGL_SUBRESOURCE_LAYOUT layout; |
| 440 | XGL_SIZE layout_size; |
| 441 | XGL_VOID *data; |
| 442 | XGL_INT x, y; |
Cody Northrop | 350727b | 2014-10-06 15:42:00 -0600 | [diff] [blame] | 443 | |
Cody Northrop | 904742c | 2014-10-07 16:25:00 -0600 | [diff] [blame] | 444 | err = xglGetImageSubresourceInfo(m_texture, &subres, |
| 445 | XGL_INFO_TYPE_SUBRESOURCE_LAYOUT, &layout_size, &layout); |
| 446 | assert(!err && layout_size == sizeof(layout)); |
Cody Northrop | 350727b | 2014-10-06 15:42:00 -0600 | [diff] [blame] | 447 | |
Cody Northrop | 904742c | 2014-10-07 16:25:00 -0600 | [diff] [blame] | 448 | err = xglMapMemory(m_textureMem, 0, &data); |
| 449 | assert(!err); |
Cody Northrop | 350727b | 2014-10-06 15:42:00 -0600 | [diff] [blame] | 450 | |
Cody Northrop | 904742c | 2014-10-07 16:25:00 -0600 | [diff] [blame] | 451 | for (y = 0; y < tex_height; y++) { |
| 452 | uint32_t *row = (uint32_t *) ((char *) data + layout.rowPitch * y); |
| 453 | for (x = 0; x < tex_width; x++) |
| 454 | row[x] = tex_colors[i][(x & 1) ^ (y & 1)]; |
Cody Northrop | 350727b | 2014-10-06 15:42:00 -0600 | [diff] [blame] | 455 | } |
Cody Northrop | 904742c | 2014-10-07 16:25:00 -0600 | [diff] [blame] | 456 | |
| 457 | err = xglUnmapMemory(m_textureMem); |
| 458 | assert(!err); |
Cody Northrop | 350727b | 2014-10-06 15:42:00 -0600 | [diff] [blame] | 459 | } |
| 460 | |
Cody Northrop | 350727b | 2014-10-06 15:42:00 -0600 | [diff] [blame] | 461 | m_textureViewInfo.view = m_textureView; |
| 462 | } |
| 463 | |
| 464 | void XglRenderTest::InitSampler() |
| 465 | { |
| 466 | XGL_RESULT err; |
| 467 | |
| 468 | XGL_SAMPLER_CREATE_INFO samplerCreateInfo = {}; |
| 469 | samplerCreateInfo.sType = XGL_STRUCTURE_TYPE_SAMPLER_CREATE_INFO; |
| 470 | samplerCreateInfo.magFilter = XGL_TEX_FILTER_NEAREST; |
| 471 | samplerCreateInfo.minFilter = XGL_TEX_FILTER_NEAREST; |
| 472 | samplerCreateInfo.mipMode = XGL_TEX_MIPMAP_BASE; |
| 473 | samplerCreateInfo.addressU = XGL_TEX_ADDRESS_WRAP; |
| 474 | samplerCreateInfo.addressV = XGL_TEX_ADDRESS_WRAP; |
| 475 | samplerCreateInfo.addressW = XGL_TEX_ADDRESS_WRAP; |
| 476 | samplerCreateInfo.mipLodBias = 0.0; |
| 477 | samplerCreateInfo.maxAnisotropy = 0.0; |
| 478 | samplerCreateInfo.compareFunc = XGL_COMPARE_NEVER; |
| 479 | samplerCreateInfo.minLod = 0.0; |
| 480 | samplerCreateInfo.maxLod = 0.0; |
| 481 | samplerCreateInfo.borderColorType = XGL_BORDER_COLOR_OPAQUE_WHITE; |
| 482 | |
| 483 | err = xglCreateSampler(device(),&samplerCreateInfo, &m_sampler); |
| 484 | ASSERT_XGL_SUCCESS(err); |
| 485 | } |
| 486 | |
Courtney Goeltzenleuchter | cb5a89c | 2014-10-08 12:20:26 -0600 | [diff] [blame^] | 487 | void XglRenderTest::NewGenerateClearAndPrepareBufferCmds(XglImage *renderTarget) |
Tobin Ehlis | 34e0e44 | 2014-10-07 14:41:29 -0600 | [diff] [blame] | 488 | { |
Courtney Goeltzenleuchter | a948d84 | 2014-08-22 16:27:58 -0600 | [diff] [blame] | 489 | // whatever we want to do, we do it to the whole buffer |
| 490 | XGL_IMAGE_SUBRESOURCE_RANGE srRange = {}; |
| 491 | srRange.aspect = XGL_IMAGE_ASPECT_COLOR; |
| 492 | srRange.baseMipLevel = 0; |
| 493 | srRange.mipLevels = XGL_LAST_MIP_OR_SLICE; |
| 494 | srRange.baseArraySlice = 0; |
| 495 | srRange.arraySize = XGL_LAST_MIP_OR_SLICE; |
| 496 | |
| 497 | // prepare the whole back buffer for clear |
| 498 | XGL_IMAGE_STATE_TRANSITION transitionToClear = {}; |
Courtney Goeltzenleuchter | 04814f8 | 2014-09-01 16:37:18 -0600 | [diff] [blame] | 499 | transitionToClear.image = renderTarget->image(); |
| 500 | transitionToClear.oldState = renderTarget->state(); |
Courtney Goeltzenleuchter | a948d84 | 2014-08-22 16:27:58 -0600 | [diff] [blame] | 501 | transitionToClear.newState = XGL_IMAGE_STATE_CLEAR; |
| 502 | transitionToClear.subresourceRange = srRange; |
| 503 | xglCmdPrepareImages( m_cmdBuffer, 1, &transitionToClear ); |
Courtney Goeltzenleuchter | 04814f8 | 2014-09-01 16:37:18 -0600 | [diff] [blame] | 504 | renderTarget->state(( XGL_IMAGE_STATE ) transitionToClear.newState); |
Courtney Goeltzenleuchter | a948d84 | 2014-08-22 16:27:58 -0600 | [diff] [blame] | 505 | |
| 506 | // clear the back buffer to dark grey |
| 507 | XGL_UINT clearColor[4] = {64, 64, 64, 0}; |
Courtney Goeltzenleuchter | 04814f8 | 2014-09-01 16:37:18 -0600 | [diff] [blame] | 508 | xglCmdClearColorImageRaw( m_cmdBuffer, renderTarget->image(), clearColor, 1, &srRange ); |
Courtney Goeltzenleuchter | a948d84 | 2014-08-22 16:27:58 -0600 | [diff] [blame] | 509 | |
| 510 | // prepare back buffer for rendering |
| 511 | XGL_IMAGE_STATE_TRANSITION transitionToRender = {}; |
Courtney Goeltzenleuchter | 04814f8 | 2014-09-01 16:37:18 -0600 | [diff] [blame] | 512 | transitionToRender.image = renderTarget->image(); |
| 513 | transitionToRender.oldState = renderTarget->state(); |
Courtney Goeltzenleuchter | a948d84 | 2014-08-22 16:27:58 -0600 | [diff] [blame] | 514 | transitionToRender.newState = XGL_IMAGE_STATE_TARGET_RENDER_ACCESS_OPTIMAL; |
| 515 | transitionToRender.subresourceRange = srRange; |
| 516 | xglCmdPrepareImages( m_cmdBuffer, 1, &transitionToRender ); |
Courtney Goeltzenleuchter | 04814f8 | 2014-09-01 16:37:18 -0600 | [diff] [blame] | 517 | renderTarget->state(( XGL_IMAGE_STATE ) transitionToClear.newState); |
Tobin Ehlis | 34e0e44 | 2014-10-07 14:41:29 -0600 | [diff] [blame] | 518 | } |
Courtney Goeltzenleuchter | a948d84 | 2014-08-22 16:27:58 -0600 | [diff] [blame] | 519 | |
Courtney Goeltzenleuchter | cb5a89c | 2014-10-08 12:20:26 -0600 | [diff] [blame^] | 520 | void XglRenderTest::NewGenerateBindStateAndPipelineCmds(XGL_PIPELINE* pipeline) |
Tobin Ehlis | 34e0e44 | 2014-10-07 14:41:29 -0600 | [diff] [blame] | 521 | { |
Courtney Goeltzenleuchter | a948d84 | 2014-08-22 16:27:58 -0600 | [diff] [blame] | 522 | // set all states |
| 523 | xglCmdBindStateObject( m_cmdBuffer, XGL_STATE_BIND_RASTER, m_stateRaster ); |
| 524 | xglCmdBindStateObject( m_cmdBuffer, XGL_STATE_BIND_VIEWPORT, m_stateViewport ); |
Courtney Goeltzenleuchter | 68cfe61 | 2014-08-26 18:16:41 -0600 | [diff] [blame] | 525 | xglCmdBindStateObject( m_cmdBuffer, XGL_STATE_BIND_COLOR_BLEND, m_colorBlend); |
Courtney Goeltzenleuchter | a948d84 | 2014-08-22 16:27:58 -0600 | [diff] [blame] | 526 | xglCmdBindStateObject( m_cmdBuffer, XGL_STATE_BIND_DEPTH_STENCIL, m_stateDepthStencil ); |
| 527 | xglCmdBindStateObject( m_cmdBuffer, XGL_STATE_BIND_MSAA, m_stateMsaa ); |
| 528 | |
| 529 | // bind pipeline, vertex buffer (descriptor set) and WVP (dynamic memory view) |
Tobin Ehlis | 34e0e44 | 2014-10-07 14:41:29 -0600 | [diff] [blame] | 530 | xglCmdBindPipeline( m_cmdBuffer, XGL_PIPELINE_BIND_POINT_GRAPHICS, *pipeline ); |
| 531 | } |
| 532 | |
| 533 | void XglRenderTest::DrawRotatedTriangleTest() |
| 534 | { |
| 535 | // TODO : This test will pass a matrix into VS to affect triangle orientation. |
| 536 | } |
| 537 | |
| 538 | void XglRenderTest::DrawTriangleTest() |
| 539 | { |
| 540 | XGL_PIPELINE pipeline; |
| 541 | XGL_SHADER vs, ps; |
| 542 | XGL_RESULT err; |
| 543 | int width = 256, height = 256; |
Tobin Ehlis | 34e0e44 | 2014-10-07 14:41:29 -0600 | [diff] [blame] | 544 | |
Courtney Goeltzenleuchter | cb5a89c | 2014-10-08 12:20:26 -0600 | [diff] [blame^] | 545 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 546 | ASSERT_NO_FATAL_FAILURE(InitViewport(256.0, 256.0)); |
| 547 | ASSERT_NO_FATAL_FAILURE(CreateDefaultPipeline(&pipeline, &vs, &ps)); |
Tobin Ehlis | 34e0e44 | 2014-10-07 14:41:29 -0600 | [diff] [blame] | 548 | |
| 549 | /* |
| 550 | * Shaders are now part of the pipeline, don't need these anymore |
| 551 | */ |
| 552 | ASSERT_XGL_SUCCESS(xglDestroyObject(ps)); |
| 553 | ASSERT_XGL_SUCCESS(xglDestroyObject(vs)); |
| 554 | |
| 555 | XGL_QUERY_POOL query; |
| 556 | XGL_GPU_MEMORY query_mem; |
| 557 | ASSERT_NO_FATAL_FAILURE(CreateQueryPool(XGL_QUERY_PIPELINE_STATISTICS, 1, &query, &query_mem)); |
| 558 | |
| 559 | XglImage *renderTarget; |
| 560 | XGL_FORMAT fmt = { |
| 561 | XGL_CH_FMT_R8G8B8A8, |
| 562 | XGL_NUM_FMT_UNORM |
| 563 | }; |
| 564 | ASSERT_NO_FATAL_FAILURE(m_device->CreateImage(width, height, fmt, |
| 565 | XGL_IMAGE_USAGE_SHADER_ACCESS_WRITE_BIT | |
| 566 | XGL_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, |
| 567 | &renderTarget)); |
| 568 | |
Cody Northrop | 342912c | 2014-10-01 14:03:25 -0600 | [diff] [blame] | 569 | const int constantCount = 4; |
| 570 | const float constants[constantCount] = { 0.5, 0.5, 0.5, 1.0 }; |
| 571 | InitConstantBuffer(constantCount, sizeof(constants[0]), (const void*) constants); |
| 572 | |
| 573 | // Create descriptor set for a uniform resource |
| 574 | XGL_DESCRIPTOR_SET_CREATE_INFO descriptorInfo = {}; |
| 575 | descriptorInfo.sType = XGL_STRUCTURE_TYPE_DESCRIPTOR_SET_CREATE_INFO; |
| 576 | descriptorInfo.slots = 1; |
| 577 | |
| 578 | // create a descriptor set with a single slot |
| 579 | err = xglCreateDescriptorSet( device(), &descriptorInfo, &m_rsrcDescSet ); |
| 580 | ASSERT_XGL_SUCCESS(err) << "xglCreateDescriptorSet failed"; |
| 581 | |
| 582 | // bind memory to the descriptor set |
| 583 | err = m_device->AllocAndBindGpuMemory(m_rsrcDescSet, "DescriptorSet", &m_descriptor_set_mem); |
| 584 | |
| 585 | // write the constant buffer view to the descriptor set |
| 586 | xglBeginDescriptorSetUpdate( m_rsrcDescSet ); |
| 587 | xglAttachMemoryViewDescriptors( m_rsrcDescSet, 0, 1, &m_constantBufferView ); |
| 588 | xglEndDescriptorSetUpdate( m_rsrcDescSet ); |
| 589 | |
Tobin Ehlis | 34e0e44 | 2014-10-07 14:41:29 -0600 | [diff] [blame] | 590 | // Build command buffer |
| 591 | err = xglBeginCommandBuffer(m_cmdBuffer, 0); |
| 592 | ASSERT_XGL_SUCCESS(err); |
| 593 | |
| 594 | GenerateClearAndPrepareBufferCmds(renderTarget); |
| 595 | GenerateBindRenderTargetCmd(renderTarget); |
| 596 | GenerateBindStateAndPipelineCmds(&pipeline); |
| 597 | |
Courtney Goeltzenleuchter | a948d84 | 2014-08-22 16:27:58 -0600 | [diff] [blame] | 598 | // xglCmdBindDescriptorSet(m_cmdBuffer, XGL_PIPELINE_BIND_POINT_GRAPHICS, 0, m_rsrcDescSet, 0 ); |
Cody Northrop | 2c4c6d9 | 2014-10-01 14:03:25 -0600 | [diff] [blame] | 599 | xglCmdBindDescriptorSet(m_cmdBuffer, XGL_PIPELINE_BIND_POINT_GRAPHICS, 0, m_rsrcDescSet, 0 ); |
Tobin Ehlis | cf9489b | 2014-10-07 14:41:29 -0600 | [diff] [blame] | 600 | } |
| 601 | |
| 602 | void XglRenderTest::DrawRotatedTriangleTest() |
| 603 | { |
| 604 | // TODO : This test will pass a matrix into VS to affect triangle orientation. |
| 605 | } |
| 606 | |
| 607 | void XglRenderTest::DrawTriangleTest() |
| 608 | { |
| 609 | XGL_PIPELINE pipeline; |
| 610 | XGL_SHADER vs, ps; |
| 611 | XGL_RESULT err; |
| 612 | int width = 256, height = 256; |
| 613 | CreateDefaultPipeline(&pipeline, &vs, &ps, width, height); |
| 614 | //ASSERT_XGL_SUCCESS(err); |
| 615 | |
| 616 | err = m_device->AllocAndBindGpuMemory(pipeline, "Pipeline", &m_pipe_mem); |
| 617 | ASSERT_XGL_SUCCESS(err); |
| 618 | |
| 619 | /* |
| 620 | * Shaders are now part of the pipeline, don't need these anymore |
| 621 | */ |
| 622 | ASSERT_XGL_SUCCESS(xglDestroyObject(ps)); |
| 623 | ASSERT_XGL_SUCCESS(xglDestroyObject(vs)); |
| 624 | |
| 625 | XGL_QUERY_POOL query; |
| 626 | XGL_GPU_MEMORY query_mem; |
| 627 | ASSERT_NO_FATAL_FAILURE(CreateQueryPool(XGL_QUERY_PIPELINE_STATISTICS, 1, &query, &query_mem)); |
| 628 | |
| 629 | XglImage *renderTarget; |
| 630 | XGL_FORMAT fmt = { |
| 631 | XGL_CH_FMT_R8G8B8A8, |
| 632 | XGL_NUM_FMT_UNORM |
| 633 | }; |
| 634 | ASSERT_NO_FATAL_FAILURE(m_device->CreateImage(width, height, fmt, |
| 635 | XGL_IMAGE_USAGE_SHADER_ACCESS_WRITE_BIT | |
| 636 | XGL_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, |
| 637 | &renderTarget)); |
| 638 | |
| 639 | // Build command buffer |
| 640 | err = xglBeginCommandBuffer(m_cmdBuffer, 0); |
| 641 | ASSERT_XGL_SUCCESS(err); |
| 642 | |
Courtney Goeltzenleuchter | cb5a89c | 2014-10-08 12:20:26 -0600 | [diff] [blame^] | 643 | NewGenerateClearAndPrepareBufferCmds(renderTarget); |
Tobin Ehlis | cf9489b | 2014-10-07 14:41:29 -0600 | [diff] [blame] | 644 | GenerateBindRenderTargetCmd(renderTarget); |
Courtney Goeltzenleuchter | cb5a89c | 2014-10-08 12:20:26 -0600 | [diff] [blame^] | 645 | NewGenerateBindStateAndPipelineCmds(&pipeline); |
Tobin Ehlis | cf9489b | 2014-10-07 14:41:29 -0600 | [diff] [blame] | 646 | |
| 647 | // xglCmdBindDescriptorSet(m_cmdBuffer, XGL_PIPELINE_BIND_POINT_GRAPHICS, 0, m_rsrcDescSet, 0 ); |
Courtney Goeltzenleuchter | a948d84 | 2014-08-22 16:27:58 -0600 | [diff] [blame] | 648 | // xglCmdBindDynamicMemoryView( m_cmdBuffer, XGL_PIPELINE_BIND_POINT_GRAPHICS, &m_constantBufferView ); |
| 649 | |
Chia-I Wu | f070ec1 | 2014-08-30 23:58:36 +0800 | [diff] [blame] | 650 | xglCmdResetQueryPool(m_cmdBuffer, query, 0, 1); |
| 651 | xglCmdBeginQuery(m_cmdBuffer, query, 0, 0); |
| 652 | |
Courtney Goeltzenleuchter | a948d84 | 2014-08-22 16:27:58 -0600 | [diff] [blame] | 653 | // render the cube |
| 654 | xglCmdDraw( m_cmdBuffer, 0, 3, 0, 1 ); |
| 655 | |
Chia-I Wu | f070ec1 | 2014-08-30 23:58:36 +0800 | [diff] [blame] | 656 | xglCmdEndQuery(m_cmdBuffer, query, 0); |
| 657 | |
Courtney Goeltzenleuchter | a948d84 | 2014-08-22 16:27:58 -0600 | [diff] [blame] | 658 | // prepare the back buffer for present |
| 659 | // XGL_IMAGE_STATE_TRANSITION transitionToPresent = {}; |
| 660 | // transitionToPresent.image = m_image; |
| 661 | // transitionToPresent.oldState = m_image_state; |
| 662 | // transitionToPresent.newState = m_display.fullscreen ? XGL_WSI_WIN_PRESENT_SOURCE_FLIP : XGL_WSI_WIN_PRESENT_SOURCE_BLT; |
| 663 | // transitionToPresent.subresourceRange = srRange; |
| 664 | // xglCmdPrepareImages( m_cmdBuffer, 1, &transitionToPresent ); |
| 665 | // m_image_state = ( XGL_IMAGE_STATE ) transitionToPresent.newState; |
| 666 | |
| 667 | // finalize recording of the command buffer |
| 668 | err = xglEndCommandBuffer( m_cmdBuffer ); |
| 669 | ASSERT_XGL_SUCCESS( err ); |
| 670 | |
| 671 | // this command buffer only uses the vertex buffer memory |
| 672 | m_numMemRefs = 0; |
| 673 | // m_memRefs[0].flags = 0; |
| 674 | // m_memRefs[0].mem = m_vtxBufferMemory; |
| 675 | |
| 676 | // submit the command buffer to the universal queue |
| 677 | err = xglQueueSubmit( m_device->m_queue, 1, &m_cmdBuffer, m_numMemRefs, m_memRefs, NULL ); |
| 678 | ASSERT_XGL_SUCCESS( err ); |
| 679 | |
Chia-I Wu | f34ac50 | 2014-08-27 14:58:05 +0800 | [diff] [blame] | 680 | err = xglQueueWaitIdle( m_device->m_queue ); |
| 681 | ASSERT_XGL_SUCCESS( err ); |
| 682 | |
Courtney Goeltzenleuchter | 68cfe61 | 2014-08-26 18:16:41 -0600 | [diff] [blame] | 683 | // Wait for work to finish before cleaning up. |
| 684 | xglDeviceWaitIdle(m_device->device()); |
| 685 | |
Chia-I Wu | f070ec1 | 2014-08-30 23:58:36 +0800 | [diff] [blame] | 686 | XGL_PIPELINE_STATISTICS_DATA stats; |
Jon Ashburn | b8e4389 | 2014-09-25 14:36:58 -0600 | [diff] [blame] | 687 | XGL_SIZE stats_size = sizeof(stats); |
Chia-I Wu | f070ec1 | 2014-08-30 23:58:36 +0800 | [diff] [blame] | 688 | err = xglGetQueryPoolResults(query, 0, 1, &stats_size, &stats); |
| 689 | ASSERT_XGL_SUCCESS( err ); |
| 690 | ASSERT_EQ(stats_size, sizeof(stats)); |
| 691 | |
| 692 | ASSERT_EQ(stats.vsInvocations, 3); |
| 693 | ASSERT_EQ(stats.cPrimitives, 1); |
| 694 | ASSERT_EQ(stats.cInvocations, 1); |
| 695 | |
| 696 | DestroyQueryPool(query, query_mem); |
| 697 | |
Courtney Goeltzenleuchter | 04814f8 | 2014-09-01 16:37:18 -0600 | [diff] [blame] | 698 | const ::testing::TestInfo* const test_info = |
| 699 | ::testing::UnitTest::GetInstance()->current_test_info(); |
| 700 | |
Courtney Goeltzenleuchter | 2802979 | 2014-09-04 16:26:02 -0600 | [diff] [blame] | 701 | // renderTarget->WritePPM(test_info->test_case_name()); |
Courtney Goeltzenleuchter | 04814f8 | 2014-09-01 16:37:18 -0600 | [diff] [blame] | 702 | // m_screen.Display(renderTarget, m_image_mem); |
Courtney Goeltzenleuchter | 2802979 | 2014-09-04 16:26:02 -0600 | [diff] [blame] | 703 | RecordImage(renderTarget); |
Chia-I Wu | f34ac50 | 2014-08-27 14:58:05 +0800 | [diff] [blame] | 704 | |
Courtney Goeltzenleuchter | 04814f8 | 2014-09-01 16:37:18 -0600 | [diff] [blame] | 705 | free(renderTarget); |
Courtney Goeltzenleuchter | a948d84 | 2014-08-22 16:27:58 -0600 | [diff] [blame] | 706 | } |
| 707 | |
Chia-I Wu | f34ac50 | 2014-08-27 14:58:05 +0800 | [diff] [blame] | 708 | |
Courtney Goeltzenleuchter | a948d84 | 2014-08-22 16:27:58 -0600 | [diff] [blame] | 709 | TEST_F(XglRenderTest, TestDrawTriangle) { |
| 710 | DrawTriangleTest(); |
Courtney Goeltzenleuchter | b85c581 | 2014-08-19 18:35:50 -0600 | [diff] [blame] | 711 | } |
| 712 | |
Tobin Ehlis | 34e0e44 | 2014-10-07 14:41:29 -0600 | [diff] [blame] | 713 | TEST_F(XglRenderTest, TestDrawRotatedTriangle) { |
| 714 | DrawRotatedTriangleTest(); |
| 715 | } |
| 716 | |
Courtney Goeltzenleuchter | b85c581 | 2014-08-19 18:35:50 -0600 | [diff] [blame] | 717 | int main(int argc, char **argv) { |
Courtney Goeltzenleuchter | 2802979 | 2014-09-04 16:26:02 -0600 | [diff] [blame] | 718 | int result; |
| 719 | |
Courtney Goeltzenleuchter | b85c581 | 2014-08-19 18:35:50 -0600 | [diff] [blame] | 720 | ::testing::InitGoogleTest(&argc, argv); |
Courtney Goeltzenleuchter | 2802979 | 2014-09-04 16:26:02 -0600 | [diff] [blame] | 721 | XglTestFramework::InitArgs(&argc, argv); |
| 722 | |
Courtney Goeltzenleuchter | f12c776 | 2014-10-08 08:46:51 -0600 | [diff] [blame] | 723 | ::testing::Environment* const xgl_test_env = ::testing::AddGlobalTestEnvironment(new TestEnvironment); |
| 724 | |
Courtney Goeltzenleuchter | 2802979 | 2014-09-04 16:26:02 -0600 | [diff] [blame] | 725 | result = RUN_ALL_TESTS(); |
| 726 | |
| 727 | XglTestFramework::Finish(); |
| 728 | return result; |
Courtney Goeltzenleuchter | b85c581 | 2014-08-19 18:35:50 -0600 | [diff] [blame] | 729 | } |