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> |
| 65 | #include "gtest-1.7.0/include/gtest/gtest.h" |
| 66 | |
| 67 | #include "xgldevice.h" |
Courtney Goeltzenleuchter | 04814f8 | 2014-09-01 16:37:18 -0600 | [diff] [blame] | 68 | #include "xglimage.h" |
Chia-I Wu | 4115c89 | 2014-08-28 11:56:29 +0800 | [diff] [blame] | 69 | #include "icd-bil.h" |
Courtney Goeltzenleuchter | b85c581 | 2014-08-19 18:35:50 -0600 | [diff] [blame] | 70 | |
Courtney Goeltzenleuchter | 2802979 | 2014-09-04 16:26:02 -0600 | [diff] [blame] | 71 | #include "xgltestframework.h" |
Courtney Goeltzenleuchter | 2268d1e | 2014-09-01 13:57:15 -0600 | [diff] [blame] | 72 | |
Courtney Goeltzenleuchter | a948d84 | 2014-08-22 16:27:58 -0600 | [diff] [blame] | 73 | //-------------------------------------------------------------------------------------- |
| 74 | // Mesh and VertexFormat Data |
| 75 | //-------------------------------------------------------------------------------------- |
| 76 | struct Vertex |
| 77 | { |
| 78 | XGL_FLOAT posX, posY, posZ, posW; // Position data |
| 79 | XGL_FLOAT r, g, b, a; // Color |
| 80 | }; |
| 81 | |
| 82 | #define XYZ1(_x_, _y_, _z_) (_x_), (_y_), (_z_), 1.f |
| 83 | |
| 84 | static const Vertex g_vbData[] = |
| 85 | { |
| 86 | { XYZ1( -1, -1, -1 ), XYZ1( 0.f, 0.f, 0.f ) }, |
| 87 | { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) }, |
| 88 | { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) }, |
| 89 | { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) }, |
| 90 | { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) }, |
| 91 | { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) }, |
| 92 | |
| 93 | { XYZ1( -1, -1, 1 ), XYZ1( 0.f, 0.f, 1.f ) }, |
| 94 | { XYZ1( -1, 1, 1 ), XYZ1( 0.f, 1.f, 1.f ) }, |
| 95 | { XYZ1( 1, -1, 1 ), XYZ1( 1.f, 0.f, 1.f ) }, |
| 96 | { XYZ1( 1, -1, 1 ), XYZ1( 1.f, 0.f, 1.f ) }, |
| 97 | { XYZ1( -1, 1, 1 ), XYZ1( 0.f, 1.f, 1.f ) }, |
| 98 | { XYZ1( 1, 1, 1 ), XYZ1( 1.f, 1.f, 1.f ) }, |
| 99 | |
| 100 | { XYZ1( 1, 1, 1 ), XYZ1( 1.f, 1.f, 1.f ) }, |
| 101 | { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) }, |
| 102 | { XYZ1( 1, -1, 1 ), XYZ1( 1.f, 0.f, 1.f ) }, |
| 103 | { XYZ1( 1, -1, 1 ), XYZ1( 1.f, 0.f, 1.f ) }, |
| 104 | { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) }, |
| 105 | { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) }, |
| 106 | |
| 107 | { XYZ1( -1, 1, 1 ), XYZ1( 0.f, 1.f, 1.f ) }, |
| 108 | { XYZ1( -1, -1, 1 ), XYZ1( 0.f, 0.f, 1.f ) }, |
| 109 | { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) }, |
| 110 | { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) }, |
| 111 | { XYZ1( -1, -1, 1 ), XYZ1( 0.f, 0.f, 1.f ) }, |
| 112 | { XYZ1( -1, -1, -1 ), XYZ1( 0.f, 0.f, 0.f ) }, |
| 113 | |
| 114 | { XYZ1( 1, 1, 1 ), XYZ1( 1.f, 1.f, 1.f ) }, |
| 115 | { XYZ1( -1, 1, 1 ), XYZ1( 0.f, 1.f, 1.f ) }, |
| 116 | { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) }, |
| 117 | { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) }, |
| 118 | { XYZ1( -1, 1, 1 ), XYZ1( 0.f, 1.f, 1.f ) }, |
| 119 | { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) }, |
| 120 | |
| 121 | { XYZ1( 1, -1, 1 ), XYZ1( 1.f, 0.f, 1.f ) }, |
| 122 | { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) }, |
| 123 | { XYZ1( -1, -1, 1 ), XYZ1( 0.f, 0.f, 1.f ) }, |
| 124 | { XYZ1( -1, -1, 1 ), XYZ1( 0.f, 0.f, 1.f ) }, |
| 125 | { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) }, |
| 126 | { XYZ1( -1, -1, -1 ), XYZ1( 0.f, 0.f, 0.f ) }, |
| 127 | }; |
| 128 | |
Chia-I Wu | 6e9789c | 2014-08-30 14:03:32 +0800 | [diff] [blame] | 129 | static const uint32_t gen6_fs[] = { |
| 130 | 0x00600001, 0x202003fe, 0x00000000, 0x3f800000, // mov(8) m1<1>F 1F { align1 1Q }; |
| 131 | 0x00600001, 0x204003fe, 0x00000000, 0x00000000, // mov(8) m2<1>F 0F { align1 1Q }; |
| 132 | 0x00600001, 0x206003fe, 0x00000000, 0x00000000, // mov(8) m3<1>F 0F { align1 1Q }; |
| 133 | 0x00600001, 0x208003fe, 0x00000000, 0x3f800000, // mov(8) m4<1>F 1F { align1 1Q }; |
| 134 | 0x05600032, 0x20001fc8, 0x008d0020, 0x88019400, // sendc(8) null m1<8,8,1>F |
| 135 | // render RT write SIMD8 LastRT Surface = 0 mlen 4 rlen 0 { align1 1Q EOT }; |
| 136 | }; |
| 137 | |
| 138 | static const uint32_t gen6_vs[] = { |
| 139 | 0x01600110, 0x200f1ca4, 0x00600020, 0x00000000, // cmp.z.f0(8) null g1<4,4,1>.xD 0D { align16 1Q }; |
| 140 | 0x00670122, 0x000a108f, 0x000e0004, 0x000e0004, // (+f0.all4h) if(8) JIP: 10 { align16 1Q }; |
| 141 | 0x00600501, 0x204303fd, 0x00000000, 0xbf800000, // mov(8) g2<1>.xyF -1F { align16 NoDDClr 1Q }; |
| 142 | 0x00600d01, 0x204403fd, 0x00000000, 0x00000000, // mov(8) g2<1>.zF 0F { align16 NoDDClr,NoDDChk 1Q }; |
| 143 | 0x00600901, 0x204803fd, 0x00000000, 0x3f800000, // mov(8) g2<1>.wF 1F { align16 NoDDChk 1Q }; |
| 144 | 0x00600124, 0x0014108f, 0x006e0004, 0x006e0004, // else(8) JIP: 20 { align16 1Q }; |
| 145 | 0x01600110, 0x200f1ca4, 0x00600020, 0x00000001, // cmp.z.f0(8) null g1<4,4,1>.xD 1D { align16 1Q }; |
| 146 | 0x00670122, 0x000a108f, 0x000e0004, 0x000e0004, // (+f0.all4h) if(8) JIP: 10 { align16 1Q }; |
| 147 | 0x00600501, 0x204903fd, 0x00000000, 0x3f800000, // mov(8) g2<1>.xwF 1F { align16 NoDDClr 1Q }; |
| 148 | 0x00600d01, 0x204203fd, 0x00000000, 0xbf800000, // mov(8) g2<1>.yF -1F { align16 NoDDClr,NoDDChk 1Q }; |
| 149 | 0x00600901, 0x204403fd, 0x00000000, 0x00000000, // mov(8) g2<1>.zF 0F { align16 NoDDChk 1Q }; |
| 150 | 0x00600124, 0x0006108f, 0x006e0004, 0x006e0004, // else(8) JIP: 6 { align16 1Q }; |
| 151 | 0x00600501, 0x204503fd, 0x00000000, 0x00000000, // mov(8) g2<1>.xzF 0F { align16 NoDDClr 1Q }; |
| 152 | 0x00600901, 0x204a03fd, 0x00000000, 0x3f800000, // mov(8) g2<1>.ywF 1F { align16 NoDDChk 1Q }; |
| 153 | 0x00600125, 0x0002108f, 0x006e0004, 0x006e0002, // endif(8) JIP: 2 { align16 1Q }; |
| 154 | 0x00600125, 0x0002108f, 0x006e0004, 0x006e0002, // endif(8) JIP: 2 { align16 1Q }; |
| 155 | 0x00600101, 0x204f0062, 0x00000000, 0x00000000, // mov(8) m2<1>UD 0x00000000UD { align16 1Q }; |
| 156 | 0x00600101, 0x206f03be, 0x006e0044, 0x00000000, // mov(8) m3<1>F g2<4,4,1>F { align16 1Q }; |
| 157 | 0x00600301, 0x202f0022, 0x006e0004, 0x00000000, // mov(8) m1<1>UD g0<4,4,1>UD { align16 WE_all 1Q }; |
| 158 | 0x06600131, 0x200f1fdc, 0x006e0024, 0x8608c400, // send(8) null m1<4,4,1>F |
| 159 | // urb 0 urb_write interleave used complete mlen 3 rlen 0 { align16 1Q EOT }; |
| 160 | }; |
| 161 | |
| 162 | static const uint32_t gen7_fs[] = { |
| 163 | 0x00600001, 0x2e2003fd, 0x00000000, 0x3f800000, // mov(8) g113<1>F 1F { align1 1Q }; |
| 164 | 0x00600001, 0x2e4003fd, 0x00000000, 0x00000000, // mov(8) g114<1>F 0F { align1 1Q }; |
| 165 | 0x00600001, 0x2e6003fd, 0x00000000, 0x00000000, // mov(8) g115<1>F 0F { align1 1Q }; |
| 166 | 0x00600001, 0x2e8003fd, 0x00000000, 0x3f800000, // mov(8) g116<1>F 1F { align1 1Q }; |
| 167 | 0x05600032, 0x20001fa8, 0x008d0e20, 0x88031400, // sendc(8) null g113<8,8,1>F |
| 168 | // render RT write SIMD8 LastRT Surface = 0 mlen 4 rlen 0 { align1 1Q EOT }; |
| 169 | }; |
| 170 | |
| 171 | static const uint32_t gen7_vs[] = { |
| 172 | 0x01608110, 0x200f1ca4, 0x00600020, 0x00000000, // cmp.z.f0(8) null g1<4,4,1>.xD 0D { align16 1Q switch }; |
| 173 | 0x00670122, 0x200f0c84, 0x000e0004, 0x001c000a, // (+f0.all4h) if(8) JIP: 10 UIP: 28 { align16 1Q }; |
| 174 | 0x00600501, 0x204303fd, 0x00000000, 0xbf800000, // mov(8) g2<1>.xyF -1F { align16 NoDDClr 1Q }; |
| 175 | 0x00600d01, 0x204403fd, 0x00000000, 0x00000000, // mov(8) g2<1>.zF 0F { align16 NoDDClr,NoDDChk 1Q }; |
| 176 | 0x00600901, 0x204803fd, 0x00000000, 0x3f800000, // mov(8) g2<1>.wF 1F { align16 NoDDChk 1Q }; |
| 177 | 0x00600124, 0x200f0c84, 0x006e0004, 0x00000014, // else(8) JIP: 20 { align16 1Q }; |
| 178 | 0x01608110, 0x200f1ca4, 0x00600020, 0x00000001, // cmp.z.f0(8) null g1<4,4,1>.xD 1D { align16 1Q switch }; |
| 179 | 0x00670122, 0x200f0c84, 0x000e0004, 0x000e000a, // (+f0.all4h) if(8) JIP: 10 UIP: 14 { align16 1Q }; |
| 180 | 0x00600501, 0x204903fd, 0x00000000, 0x3f800000, // mov(8) g2<1>.xwF 1F { align16 NoDDClr 1Q }; |
| 181 | 0x00600d01, 0x204203fd, 0x00000000, 0xbf800000, // mov(8) g2<1>.yF -1F { align16 NoDDClr,NoDDChk 1Q }; |
| 182 | 0x00600901, 0x204403fd, 0x00000000, 0x00000000, // mov(8) g2<1>.zF 0F { align16 NoDDChk 1Q }; |
| 183 | 0x00600124, 0x200f0c84, 0x006e0004, 0x00000006, // else(8) JIP: 6 { align16 1Q }; |
| 184 | 0x00600501, 0x204503fd, 0x00000000, 0x00000000, // mov(8) g2<1>.xzF 0F { align16 NoDDClr 1Q }; |
| 185 | 0x00600901, 0x204a03fd, 0x00000000, 0x3f800000, // mov(8) g2<1>.ywF 1F { align16 NoDDChk 1Q }; |
| 186 | 0x00600125, 0x200f0c84, 0x006e0004, 0x00000002, // endif(8) JIP: 2 { align16 1Q }; |
| 187 | 0x00600125, 0x200f0c84, 0x006e0004, 0x00000002, // endif(8) JIP: 2 { align16 1Q }; |
| 188 | 0x00600101, 0x2e4f0061, 0x00000000, 0x00000000, // mov(8) g114<1>UD 0x00000000UD { align16 1Q }; |
| 189 | 0x00600101, 0x2e6f03bd, 0x006e0044, 0x00000000, // mov(8) g115<1>F g2<4,4,1>F { align16 1Q }; |
| 190 | 0x00600301, 0x2e2f0021, 0x006e0004, 0x00000000, // mov(8) g113<1>UD g0<4,4,1>UD { align16 WE_all 1Q }; |
| 191 | 0x00000206, 0x2e340c21, 0x00000014, 0x0000ff00, // or(1) g113.5<1>UD g0.5<0,1,0>UD 0x0000ff00UD { align1 WE_all }; |
| 192 | 0x06600131, 0x200f1fbc, 0x006e0e24, 0x8608c000, // send(8) null g113<4,4,1>F |
| 193 | // urb 0 write HWord interleave complete mlen 3 rlen 0 { align16 1Q EOT }; |
| 194 | }; |
Courtney Goeltzenleuchter | a948d84 | 2014-08-22 16:27:58 -0600 | [diff] [blame] | 195 | |
Courtney Goeltzenleuchter | 2802979 | 2014-09-04 16:26:02 -0600 | [diff] [blame] | 196 | class XglRenderTest : public XglTestFramework |
| 197 | { |
Courtney Goeltzenleuchter | b85c581 | 2014-08-19 18:35:50 -0600 | [diff] [blame] | 198 | public: |
Chia-I Wu | a3b9d6a | 2014-08-30 23:53:01 +0800 | [diff] [blame] | 199 | void CreateQueryPool(XGL_QUERY_TYPE type, XGL_UINT slots, |
| 200 | XGL_QUERY_POOL *pPool, XGL_GPU_MEMORY *pMem); |
| 201 | void DestroyQueryPool(XGL_QUERY_POOL pool, XGL_GPU_MEMORY mem); |
Tobin Ehlis | 34e0e44 | 2014-10-07 14:41:29 -0600 | [diff] [blame^] | 202 | void CreateDefaultPipeline(XGL_PIPELINE* pipeline, XGL_SHADER* vs, XGL_SHADER* ps, int width, int height); |
| 203 | void GenerateClearAndPrepareBufferCmds(XglImage *renderTarget); |
| 204 | void GenerateBindRenderTargetCmd(XglImage *renderTarget); |
| 205 | void GenerateBindStateAndPipelineCmds(XGL_PIPELINE* pipeline); |
Chia-I Wu | a3b9d6a | 2014-08-30 23:53:01 +0800 | [diff] [blame] | 206 | |
Courtney Goeltzenleuchter | b85c581 | 2014-08-19 18:35:50 -0600 | [diff] [blame] | 207 | XGL_DEVICE device() {return m_device->device();} |
Chia-I Wu | 6e9789c | 2014-08-30 14:03:32 +0800 | [diff] [blame] | 208 | void CreateShader(XGL_PIPELINE_SHADER_STAGE stage, XGL_SHADER *pshader); |
Courtney Goeltzenleuchter | ac8bd17 | 2014-08-20 15:28:00 -0600 | [diff] [blame] | 209 | void InitPipeline(); |
Courtney Goeltzenleuchter | a948d84 | 2014-08-22 16:27:58 -0600 | [diff] [blame] | 210 | void InitMesh( XGL_UINT32 numVertices, XGL_GPU_SIZE vbStride, const void* vertices ); |
| 211 | void DrawTriangleTest(); |
Tobin Ehlis | 34e0e44 | 2014-10-07 14:41:29 -0600 | [diff] [blame^] | 212 | void DrawRotatedTriangleTest(); |
Courtney Goeltzenleuchter | b85c581 | 2014-08-19 18:35:50 -0600 | [diff] [blame] | 213 | |
| 214 | protected: |
| 215 | XGL_APPLICATION_INFO app_info; |
| 216 | XGL_PHYSICAL_GPU objs[MAX_GPUS]; |
| 217 | XGL_UINT gpu_count; |
Courtney Goeltzenleuchter | a948d84 | 2014-08-22 16:27:58 -0600 | [diff] [blame] | 218 | XGL_GPU_MEMORY m_descriptor_set_mem; |
| 219 | XGL_GPU_MEMORY m_pipe_mem; |
Courtney Goeltzenleuchter | b85c581 | 2014-08-19 18:35:50 -0600 | [diff] [blame] | 220 | XglDevice *m_device; |
Courtney Goeltzenleuchter | ac8bd17 | 2014-08-20 15:28:00 -0600 | [diff] [blame] | 221 | XGL_CMD_BUFFER m_cmdBuffer; |
Courtney Goeltzenleuchter | a948d84 | 2014-08-22 16:27:58 -0600 | [diff] [blame] | 222 | XGL_UINT32 m_numVertices; |
| 223 | XGL_MEMORY_VIEW_ATTACH_INFO m_vtxBufferView; |
| 224 | XGL_GPU_MEMORY m_vtxBufferMem; |
| 225 | XGL_UINT32 m_numMemRefs; |
| 226 | XGL_MEMORY_REF m_memRefs[5]; |
| 227 | XGL_RASTER_STATE_OBJECT m_stateRaster; |
Courtney Goeltzenleuchter | 68cfe61 | 2014-08-26 18:16:41 -0600 | [diff] [blame] | 228 | XGL_COLOR_BLEND_STATE_OBJECT m_colorBlend; |
Courtney Goeltzenleuchter | a948d84 | 2014-08-22 16:27:58 -0600 | [diff] [blame] | 229 | XGL_VIEWPORT_STATE_OBJECT m_stateViewport; |
| 230 | XGL_DEPTH_STENCIL_STATE_OBJECT m_stateDepthStencil; |
| 231 | XGL_MSAA_STATE_OBJECT m_stateMsaa; |
| 232 | XGL_DESCRIPTOR_SET m_rsrcDescSet; |
Courtney Goeltzenleuchter | b85c581 | 2014-08-19 18:35:50 -0600 | [diff] [blame] | 233 | |
| 234 | virtual void SetUp() { |
| 235 | XGL_RESULT err; |
| 236 | |
| 237 | this->app_info.sType = XGL_STRUCTURE_TYPE_APPLICATION_INFO; |
| 238 | this->app_info.pNext = NULL; |
| 239 | this->app_info.pAppName = (const XGL_CHAR *) "base"; |
| 240 | this->app_info.appVersion = 1; |
| 241 | this->app_info.pEngineName = (const XGL_CHAR *) "unittest"; |
| 242 | this->app_info.engineVersion = 1; |
| 243 | this->app_info.apiVersion = XGL_MAKE_VERSION(0, 22, 0); |
| 244 | |
Courtney Goeltzenleuchter | a948d84 | 2014-08-22 16:27:58 -0600 | [diff] [blame] | 245 | memset(&m_vtxBufferView, 0, sizeof(m_vtxBufferView)); |
| 246 | m_vtxBufferView.sType = XGL_STRUCTURE_TYPE_MEMORY_VIEW_ATTACH_INFO; |
| 247 | |
Courtney Goeltzenleuchter | b85c581 | 2014-08-19 18:35:50 -0600 | [diff] [blame] | 248 | err = xglInitAndEnumerateGpus(&app_info, NULL, |
| 249 | MAX_GPUS, &this->gpu_count, objs); |
| 250 | ASSERT_XGL_SUCCESS(err); |
| 251 | ASSERT_GE(1, this->gpu_count) << "No GPU available"; |
| 252 | |
| 253 | m_device = new XglDevice(0, objs[0]); |
| 254 | m_device->get_device_queue(); |
| 255 | } |
| 256 | |
| 257 | virtual void TearDown() { |
| 258 | xglInitAndEnumerateGpus(&this->app_info, XGL_NULL_HANDLE, 0, &gpu_count, XGL_NULL_HANDLE); |
| 259 | } |
| 260 | }; |
| 261 | |
Courtney Goeltzenleuchter | b85c581 | 2014-08-19 18:35:50 -0600 | [diff] [blame] | 262 | |
Chia-I Wu | a3b9d6a | 2014-08-30 23:53:01 +0800 | [diff] [blame] | 263 | void XglRenderTest::CreateQueryPool(XGL_QUERY_TYPE type, XGL_UINT slots, |
| 264 | XGL_QUERY_POOL *pPool, XGL_GPU_MEMORY *pMem) |
| 265 | { |
| 266 | XGL_RESULT err; |
| 267 | |
| 268 | XGL_QUERY_POOL_CREATE_INFO poolCreateInfo = {}; |
| 269 | poolCreateInfo.sType = XGL_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO; |
| 270 | poolCreateInfo.pNext = NULL; |
| 271 | poolCreateInfo.queryType = type; |
| 272 | poolCreateInfo.slots = slots; |
| 273 | |
| 274 | err = xglCreateQueryPool(device(), &poolCreateInfo, pPool); |
| 275 | ASSERT_XGL_SUCCESS(err); |
| 276 | |
| 277 | XGL_MEMORY_REQUIREMENTS mem_req; |
Jon Ashburn | b8e4389 | 2014-09-25 14:36:58 -0600 | [diff] [blame] | 278 | XGL_UINT data_size = sizeof(mem_req); |
Chia-I Wu | a3b9d6a | 2014-08-30 23:53:01 +0800 | [diff] [blame] | 279 | err = xglGetObjectInfo(*pPool, XGL_INFO_TYPE_MEMORY_REQUIREMENTS, |
| 280 | &data_size, &mem_req); |
| 281 | ASSERT_XGL_SUCCESS(err); |
| 282 | ASSERT_EQ(data_size, sizeof(mem_req)); |
| 283 | |
| 284 | if (!mem_req.size) { |
| 285 | *pMem = XGL_NULL_HANDLE; |
| 286 | return; |
| 287 | } |
| 288 | |
| 289 | XGL_MEMORY_ALLOC_INFO mem_info; |
| 290 | |
| 291 | memset(&mem_info, 0, sizeof(mem_info)); |
| 292 | mem_info.sType = XGL_STRUCTURE_TYPE_MEMORY_ALLOC_INFO; |
| 293 | mem_info.allocationSize = mem_req.size; |
| 294 | mem_info.alignment = mem_req.alignment; |
| 295 | mem_info.heapCount = mem_req.heapCount; |
| 296 | memcpy(mem_info.heaps, mem_req.heaps, sizeof(XGL_UINT)*XGL_MAX_MEMORY_HEAPS); |
| 297 | mem_info.memPriority = XGL_MEMORY_PRIORITY_NORMAL; |
| 298 | mem_info.flags = XGL_MEMORY_ALLOC_SHAREABLE_BIT; |
| 299 | err = xglAllocMemory(device(), &mem_info, pMem); |
| 300 | ASSERT_XGL_SUCCESS(err); |
| 301 | |
| 302 | err = xglBindObjectMemory(*pPool, *pMem, 0); |
| 303 | ASSERT_XGL_SUCCESS(err); |
| 304 | } |
| 305 | |
| 306 | void XglRenderTest::DestroyQueryPool(XGL_QUERY_POOL pool, XGL_GPU_MEMORY mem) |
| 307 | { |
| 308 | ASSERT_XGL_SUCCESS(xglBindObjectMemory(pool, XGL_NULL_HANDLE, 0)); |
| 309 | ASSERT_XGL_SUCCESS(xglFreeMemory(mem)); |
| 310 | ASSERT_XGL_SUCCESS(xglDestroyObject(pool)); |
| 311 | } |
| 312 | |
Chia-I Wu | 6e9789c | 2014-08-30 14:03:32 +0800 | [diff] [blame] | 313 | void XglRenderTest::CreateShader(XGL_PIPELINE_SHADER_STAGE stage, XGL_SHADER *pshader) |
Courtney Goeltzenleuchter | ac8bd17 | 2014-08-20 15:28:00 -0600 | [diff] [blame] | 314 | { |
Chia-I Wu | 4b7b458 | 2014-08-28 12:27:21 +0800 | [diff] [blame] | 315 | struct icd_bil_header *pBIL; |
Courtney Goeltzenleuchter | 76a643b | 2014-08-21 17:34:22 -0600 | [diff] [blame] | 316 | char * memblock; |
Chia-I Wu | 6e9789c | 2014-08-30 14:03:32 +0800 | [diff] [blame] | 317 | const char *kernel; |
| 318 | size_t kernel_size; |
Courtney Goeltzenleuchter | b85c581 | 2014-08-19 18:35:50 -0600 | [diff] [blame] | 319 | XGL_RESULT err; |
| 320 | |
Chia-I Wu | 6e9789c | 2014-08-30 14:03:32 +0800 | [diff] [blame] | 321 | const XGL_PHYSICAL_GPU_PROPERTIES *props = &m_device->props; |
| 322 | const int gen = (strstr((const char *) props->gpuName, "Sandybridge")) ? 6 : 7; |
Courtney Goeltzenleuchter | b85c581 | 2014-08-19 18:35:50 -0600 | [diff] [blame] | 323 | |
Chia-I Wu | 6e9789c | 2014-08-30 14:03:32 +0800 | [diff] [blame] | 324 | if (stage == XGL_SHADER_STAGE_VERTEX) { |
| 325 | if (gen == 6) { |
| 326 | kernel = (const char *) gen6_vs; |
| 327 | kernel_size = sizeof(gen6_vs); |
| 328 | } else { |
| 329 | kernel = (const char *) gen7_vs; |
| 330 | kernel_size = sizeof(gen7_vs); |
| 331 | } |
| 332 | } else { |
| 333 | if (gen == 6) { |
| 334 | kernel = (const char *) gen6_fs; |
| 335 | kernel_size = sizeof(gen6_fs); |
| 336 | } else { |
| 337 | kernel = (const char *) gen7_fs; |
| 338 | kernel_size = sizeof(gen7_fs); |
| 339 | } |
| 340 | } |
Courtney Goeltzenleuchter | b85c581 | 2014-08-19 18:35:50 -0600 | [diff] [blame] | 341 | |
Chia-I Wu | 6e9789c | 2014-08-30 14:03:32 +0800 | [diff] [blame] | 342 | memblock = new char [sizeof(*pBIL) + kernel_size]; |
Courtney Goeltzenleuchter | a948d84 | 2014-08-22 16:27:58 -0600 | [diff] [blame] | 343 | ASSERT_TRUE(memblock != NULL) << "memory allocation failed"; |
Courtney Goeltzenleuchter | b85c581 | 2014-08-19 18:35:50 -0600 | [diff] [blame] | 344 | |
Chia-I Wu | 4b7b458 | 2014-08-28 12:27:21 +0800 | [diff] [blame] | 345 | pBIL = (struct icd_bil_header *) memblock; |
| 346 | pBIL->magic = ICD_BIL_MAGIC; |
| 347 | pBIL->version = ICD_BIL_VERSION; |
| 348 | |
Chia-I Wu | 6e9789c | 2014-08-30 14:03:32 +0800 | [diff] [blame] | 349 | pBIL->gen_magic = (stage == XGL_SHADER_STAGE_VERTEX) ? 'v' : 'w'; |
| 350 | memcpy(pBIL + 1, kernel, kernel_size); |
Chia-I Wu | 4b7b458 | 2014-08-28 12:27:21 +0800 | [diff] [blame] | 351 | |
Courtney Goeltzenleuchter | a948d84 | 2014-08-22 16:27:58 -0600 | [diff] [blame] | 352 | XGL_SHADER_CREATE_INFO createInfo; |
| 353 | XGL_SHADER shader; |
Courtney Goeltzenleuchter | 76a643b | 2014-08-21 17:34:22 -0600 | [diff] [blame] | 354 | |
Courtney Goeltzenleuchter | a948d84 | 2014-08-22 16:27:58 -0600 | [diff] [blame] | 355 | createInfo.sType = XGL_STRUCTURE_TYPE_SHADER_CREATE_INFO; |
| 356 | createInfo.pNext = NULL; |
| 357 | createInfo.pCode = memblock; |
Chia-I Wu | 6e9789c | 2014-08-30 14:03:32 +0800 | [diff] [blame] | 358 | createInfo.codeSize = sizeof(*pBIL) + kernel_size; |
Courtney Goeltzenleuchter | a948d84 | 2014-08-22 16:27:58 -0600 | [diff] [blame] | 359 | createInfo.flags = 0; |
| 360 | err = xglCreateShader(device(), &createInfo, &shader); |
| 361 | ASSERT_XGL_SUCCESS(err); |
Courtney Goeltzenleuchter | 76a643b | 2014-08-21 17:34:22 -0600 | [diff] [blame] | 362 | |
Courtney Goeltzenleuchter | a948d84 | 2014-08-22 16:27:58 -0600 | [diff] [blame] | 363 | delete[] memblock; |
Courtney Goeltzenleuchter | 76a643b | 2014-08-21 17:34:22 -0600 | [diff] [blame] | 364 | |
Courtney Goeltzenleuchter | a948d84 | 2014-08-22 16:27:58 -0600 | [diff] [blame] | 365 | *pshader = shader; |
Courtney Goeltzenleuchter | ac8bd17 | 2014-08-20 15:28:00 -0600 | [diff] [blame] | 366 | } |
Courtney Goeltzenleuchter | b85c581 | 2014-08-19 18:35:50 -0600 | [diff] [blame] | 367 | |
Courtney Goeltzenleuchter | a948d84 | 2014-08-22 16:27:58 -0600 | [diff] [blame] | 368 | // this function will create the vertex buffer and fill it with the mesh data |
| 369 | void XglRenderTest::InitMesh( XGL_UINT32 numVertices, XGL_GPU_SIZE vbStride, |
| 370 | const void* vertices ) |
| 371 | { |
| 372 | XGL_RESULT err = XGL_SUCCESS; |
| 373 | |
| 374 | assert( numVertices * vbStride > 0 ); |
| 375 | m_numVertices = numVertices; |
| 376 | |
| 377 | XGL_MEMORY_ALLOC_INFO alloc_info = {}; |
| 378 | XGL_UINT8 *pData; |
| 379 | |
| 380 | alloc_info.sType = XGL_STRUCTURE_TYPE_MEMORY_ALLOC_INFO; |
| 381 | alloc_info.allocationSize = numVertices * vbStride; |
| 382 | alloc_info.alignment = 0; |
| 383 | alloc_info.heapCount = 1; |
| 384 | alloc_info.heaps[0] = 0; // TODO: Use known existing heap |
| 385 | |
| 386 | alloc_info.flags = XGL_MEMORY_HEAP_CPU_VISIBLE_BIT; |
| 387 | alloc_info.memPriority = XGL_MEMORY_PRIORITY_NORMAL; |
| 388 | |
| 389 | err = xglAllocMemory(device(), &alloc_info, &m_vtxBufferMem); |
| 390 | ASSERT_XGL_SUCCESS(err); |
| 391 | |
| 392 | err = xglMapMemory(m_vtxBufferMem, 0, (XGL_VOID **) &pData); |
| 393 | ASSERT_XGL_SUCCESS(err); |
| 394 | |
| 395 | memcpy(pData, vertices, alloc_info.allocationSize); |
| 396 | |
| 397 | err = xglUnmapMemory(m_vtxBufferMem); |
| 398 | ASSERT_XGL_SUCCESS(err); |
| 399 | |
| 400 | // set up the memory view for the vertex buffer |
| 401 | this->m_vtxBufferView.stride = vbStride; |
| 402 | this->m_vtxBufferView.range = numVertices * vbStride; |
| 403 | this->m_vtxBufferView.offset = 0; |
| 404 | this->m_vtxBufferView.mem = m_vtxBufferMem; |
| 405 | this->m_vtxBufferView.format.channelFormat = XGL_CH_FMT_UNDEFINED; |
| 406 | this->m_vtxBufferView.format.numericFormat = XGL_NUM_FMT_UNDEFINED; |
| 407 | |
| 408 | // open the command buffer |
| 409 | err = xglBeginCommandBuffer( m_cmdBuffer, 0 ); |
| 410 | ASSERT_XGL_SUCCESS(err); |
| 411 | |
| 412 | XGL_MEMORY_STATE_TRANSITION transition = {}; |
| 413 | transition.mem = m_vtxBufferMem; |
| 414 | transition.oldState = XGL_MEMORY_STATE_DATA_TRANSFER; |
| 415 | transition.newState = XGL_MEMORY_STATE_GRAPHICS_SHADER_READ_ONLY; |
| 416 | transition.offset = 0; |
| 417 | transition.regionSize = numVertices * vbStride; |
| 418 | |
| 419 | // write transition to the command buffer |
| 420 | xglCmdPrepareMemoryRegions( m_cmdBuffer, 1, &transition ); |
| 421 | this->m_vtxBufferView.state = XGL_MEMORY_STATE_GRAPHICS_SHADER_READ_ONLY; |
| 422 | |
| 423 | // finish recording the command buffer |
| 424 | err = xglEndCommandBuffer( m_cmdBuffer ); |
| 425 | ASSERT_XGL_SUCCESS(err); |
| 426 | |
| 427 | // this command buffer only uses the vertex buffer memory |
| 428 | m_numMemRefs = 1; |
| 429 | m_memRefs[0].flags = 0; |
| 430 | m_memRefs[0].mem = m_vtxBufferMem; |
| 431 | |
| 432 | // submit the command buffer to the universal queue |
| 433 | err = xglQueueSubmit( m_device->m_queue, 1, &m_cmdBuffer, m_numMemRefs, m_memRefs, NULL ); |
| 434 | ASSERT_XGL_SUCCESS(err); |
| 435 | } |
| 436 | |
Tobin Ehlis | 34e0e44 | 2014-10-07 14:41:29 -0600 | [diff] [blame^] | 437 | void XglRenderTest::CreateDefaultPipeline(XGL_PIPELINE* pipeline, XGL_SHADER* vs, XGL_SHADER* ps, int width, int height) |
Courtney Goeltzenleuchter | a948d84 | 2014-08-22 16:27:58 -0600 | [diff] [blame] | 438 | { |
Courtney Goeltzenleuchter | ac8bd17 | 2014-08-20 15:28:00 -0600 | [diff] [blame] | 439 | XGL_RESULT err; |
| 440 | XGL_GRAPHICS_PIPELINE_CREATE_INFO info = {}; |
Courtney Goeltzenleuchter | ac8bd17 | 2014-08-20 15:28:00 -0600 | [diff] [blame] | 441 | XGL_PIPELINE_SHADER_STAGE_CREATE_INFO vs_stage; |
| 442 | XGL_PIPELINE_SHADER_STAGE_CREATE_INFO ps_stage; |
Tobin Ehlis | 34e0e44 | 2014-10-07 14:41:29 -0600 | [diff] [blame^] | 443 | //XGL_PIPELINE pipeline; |
Courtney Goeltzenleuchter | b85c581 | 2014-08-19 18:35:50 -0600 | [diff] [blame] | 444 | |
Courtney Goeltzenleuchter | a948d84 | 2014-08-22 16:27:58 -0600 | [diff] [blame] | 445 | // create a raster state (solid, back-face culling) |
| 446 | XGL_RASTER_STATE_CREATE_INFO raster = {}; |
| 447 | raster.sType = XGL_STRUCTURE_TYPE_RASTER_STATE_CREATE_INFO; |
| 448 | raster.fillMode = XGL_FILL_SOLID; |
Chia-I Wu | 0059c37 | 2014-08-31 00:52:42 +0800 | [diff] [blame] | 449 | raster.cullMode = XGL_CULL_NONE; |
Courtney Goeltzenleuchter | a948d84 | 2014-08-22 16:27:58 -0600 | [diff] [blame] | 450 | raster.frontFace = XGL_FRONT_FACE_CCW; |
| 451 | err = xglCreateRasterState( device(), &raster, &m_stateRaster ); |
| 452 | ASSERT_XGL_SUCCESS(err); |
| 453 | |
| 454 | XGL_VIEWPORT_STATE_CREATE_INFO viewport = {}; |
| 455 | viewport.viewportCount = 1; |
| 456 | viewport.scissorEnable = XGL_FALSE; |
| 457 | viewport.viewports[0].originX = 0; |
| 458 | viewport.viewports[0].originY = 0; |
| 459 | viewport.viewports[0].width = 1.f * width; |
| 460 | viewport.viewports[0].height = 1.f * height; |
| 461 | viewport.viewports[0].minDepth = 0.f; |
| 462 | viewport.viewports[0].maxDepth = 1.f; |
| 463 | |
| 464 | err = xglCreateViewportState( device(), &viewport, &m_stateViewport ); |
| 465 | ASSERT_XGL_SUCCESS( err ); |
| 466 | |
Courtney Goeltzenleuchter | 68cfe61 | 2014-08-26 18:16:41 -0600 | [diff] [blame] | 467 | XGL_COLOR_BLEND_STATE_CREATE_INFO blend = {}; |
| 468 | blend.sType = XGL_STRUCTURE_TYPE_COLOR_BLEND_STATE_CREATE_INFO; |
| 469 | err = xglCreateColorBlendState(device(), &blend, &m_colorBlend); |
| 470 | ASSERT_XGL_SUCCESS( err ); |
| 471 | |
Courtney Goeltzenleuchter | a948d84 | 2014-08-22 16:27:58 -0600 | [diff] [blame] | 472 | XGL_DEPTH_STENCIL_STATE_CREATE_INFO depthStencil = {}; |
| 473 | depthStencil.sType = XGL_STRUCTURE_TYPE_DEPTH_STENCIL_STATE_CREATE_INFO; |
| 474 | depthStencil.depthTestEnable = XGL_FALSE; |
| 475 | depthStencil.depthWriteEnable = XGL_FALSE; |
| 476 | depthStencil.depthFunc = XGL_COMPARE_LESS_EQUAL; |
| 477 | depthStencil.depthBoundsEnable = XGL_FALSE; |
| 478 | depthStencil.minDepth = 0.f; |
| 479 | depthStencil.maxDepth = 1.f; |
| 480 | depthStencil.back.stencilDepthFailOp = XGL_STENCIL_OP_KEEP; |
| 481 | depthStencil.back.stencilFailOp = XGL_STENCIL_OP_KEEP; |
| 482 | depthStencil.back.stencilPassOp = XGL_STENCIL_OP_KEEP; |
| 483 | depthStencil.back.stencilRef = 0x00; |
| 484 | depthStencil.back.stencilFunc = XGL_COMPARE_ALWAYS; |
| 485 | depthStencil.front = depthStencil.back; |
| 486 | |
| 487 | err = xglCreateDepthStencilState( device(), &depthStencil, &m_stateDepthStencil ); |
| 488 | ASSERT_XGL_SUCCESS( err ); |
| 489 | |
| 490 | XGL_MSAA_STATE_CREATE_INFO msaa = {}; |
| 491 | msaa.sType = XGL_STRUCTURE_TYPE_MSAA_STATE_CREATE_INFO; |
| 492 | msaa.sampleMask = 1; |
| 493 | msaa.samples = 1; |
| 494 | |
| 495 | err = xglCreateMsaaState( device(), &msaa, &m_stateMsaa ); |
| 496 | ASSERT_XGL_SUCCESS( err ); |
| 497 | |
| 498 | XGL_CMD_BUFFER_CREATE_INFO cmdInfo = {}; |
| 499 | |
| 500 | cmdInfo.sType = XGL_STRUCTURE_TYPE_CMD_BUFFER_CREATE_INFO; |
| 501 | cmdInfo.queueType = XGL_QUEUE_TYPE_GRAPHICS; |
| 502 | err = xglCreateCommandBuffer(device(), &cmdInfo, &m_cmdBuffer); |
| 503 | ASSERT_XGL_SUCCESS(err) << "xglCreateCommandBuffer failed"; |
| 504 | |
Courtney Goeltzenleuchter | a948d84 | 2014-08-22 16:27:58 -0600 | [diff] [blame] | 505 | #if 0 |
| 506 | // Create descriptor set for our one resource |
| 507 | XGL_DESCRIPTOR_SET_CREATE_INFO descriptorInfo = {}; |
| 508 | descriptorInfo.sType = XGL_STRUCTURE_TYPE_DESCRIPTOR_SET_CREATE_INFO; |
| 509 | descriptorInfo.slots = 1; // Vertex buffer only |
| 510 | |
| 511 | // create a descriptor set with a single slot |
| 512 | err = xglCreateDescriptorSet( device(), &descriptorInfo, &m_rsrcDescSet ); |
| 513 | ASSERT_XGL_SUCCESS(err) << "xglCreateDescriptorSet failed"; |
| 514 | |
| 515 | // bind memory to the descriptor set |
| 516 | err = m_device->AllocAndBindGpuMemory(m_rsrcDescSet, "DescriptorSet", &m_descriptor_set_mem); |
| 517 | |
| 518 | // set up the memory view for the vertex buffer |
| 519 | this->m_vtxBufferView.stride = vbStride; |
| 520 | this->m_vtxBufferView.range = numVertices * vbStride; |
| 521 | this->m_vtxBufferView.offset = 0; |
| 522 | this->m_vtxBufferView.mem = m_vtxBufferMem; |
| 523 | this->m_vtxBufferView.format.channelFormat = XGL_CH_FMT_UNDEFINED; |
| 524 | this->m_vtxBufferView.format.numericFormat = XGL_NUM_FMT_UNDEFINED; |
| 525 | // write the vertex buffer view to the descriptor set |
| 526 | xglBeginDescriptorSetUpdate( m_rsrcDescSet ); |
| 527 | xglAttachMemoryViewDescriptors( m_rsrcDescSet, 0, 1, &m_vtxBufferView ); |
| 528 | xglEndDescriptorSetUpdate( m_rsrcDescSet ); |
| 529 | #endif |
Courtney Goeltzenleuchter | ac8bd17 | 2014-08-20 15:28:00 -0600 | [diff] [blame] | 530 | |
Tobin Ehlis | 34e0e44 | 2014-10-07 14:41:29 -0600 | [diff] [blame^] | 531 | ASSERT_NO_FATAL_FAILURE(CreateShader(XGL_SHADER_STAGE_VERTEX, vs)); |
Courtney Goeltzenleuchter | ac8bd17 | 2014-08-20 15:28:00 -0600 | [diff] [blame] | 532 | |
| 533 | vs_stage.sType = XGL_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; |
| 534 | vs_stage.pNext = XGL_NULL_HANDLE; |
| 535 | vs_stage.shader.stage = XGL_SHADER_STAGE_VERTEX; |
Tobin Ehlis | 34e0e44 | 2014-10-07 14:41:29 -0600 | [diff] [blame^] | 536 | vs_stage.shader.shader = *vs; |
Chia-I Wu | 3c89e4e | 2014-08-23 17:47:45 +0800 | [diff] [blame] | 537 | vs_stage.shader.descriptorSetMapping[0].descriptorCount = 0; |
Courtney Goeltzenleuchter | ac8bd17 | 2014-08-20 15:28:00 -0600 | [diff] [blame] | 538 | vs_stage.shader.linkConstBufferCount = 0; |
| 539 | vs_stage.shader.pLinkConstBufferInfo = XGL_NULL_HANDLE; |
Chia-I Wu | 3c89e4e | 2014-08-23 17:47:45 +0800 | [diff] [blame] | 540 | vs_stage.shader.dynamicMemoryViewMapping.slotObjectType = XGL_SLOT_UNUSED; |
Courtney Goeltzenleuchter | ac8bd17 | 2014-08-20 15:28:00 -0600 | [diff] [blame] | 541 | vs_stage.shader.dynamicMemoryViewMapping.shaderEntityIndex = 0; |
| 542 | |
Tobin Ehlis | 34e0e44 | 2014-10-07 14:41:29 -0600 | [diff] [blame^] | 543 | ASSERT_NO_FATAL_FAILURE(CreateShader(XGL_SHADER_STAGE_FRAGMENT, ps)); |
Courtney Goeltzenleuchter | ac8bd17 | 2014-08-20 15:28:00 -0600 | [diff] [blame] | 544 | |
| 545 | ps_stage.sType = XGL_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; |
| 546 | ps_stage.pNext = &vs_stage; |
| 547 | ps_stage.shader.stage = XGL_SHADER_STAGE_FRAGMENT; |
Tobin Ehlis | 34e0e44 | 2014-10-07 14:41:29 -0600 | [diff] [blame^] | 548 | ps_stage.shader.shader = *ps; |
Courtney Goeltzenleuchter | ac8bd17 | 2014-08-20 15:28:00 -0600 | [diff] [blame] | 549 | // TODO: Do we need a descriptor set mapping for fragment? |
Chia-I Wu | 3c89e4e | 2014-08-23 17:47:45 +0800 | [diff] [blame] | 550 | ps_stage.shader.descriptorSetMapping[0].descriptorCount = 0; |
Courtney Goeltzenleuchter | ac8bd17 | 2014-08-20 15:28:00 -0600 | [diff] [blame] | 551 | ps_stage.shader.linkConstBufferCount = 0; |
| 552 | ps_stage.shader.pLinkConstBufferInfo = XGL_NULL_HANDLE; |
Chia-I Wu | 3c89e4e | 2014-08-23 17:47:45 +0800 | [diff] [blame] | 553 | ps_stage.shader.dynamicMemoryViewMapping.slotObjectType = XGL_SLOT_UNUSED; |
Courtney Goeltzenleuchter | ac8bd17 | 2014-08-20 15:28:00 -0600 | [diff] [blame] | 554 | ps_stage.shader.dynamicMemoryViewMapping.shaderEntityIndex = 0; |
| 555 | |
| 556 | XGL_PIPELINE_IA_STATE_CREATE_INFO ia_state = { |
| 557 | XGL_STRUCTURE_TYPE_PIPELINE_IA_STATE_CREATE_INFO, // sType |
| 558 | &ps_stage, // pNext |
| 559 | XGL_TOPOLOGY_TRIANGLE_LIST, // XGL_PRIMITIVE_TOPOLOGY |
| 560 | XGL_FALSE, // disableVertexReuse |
| 561 | XGL_PROVOKING_VERTEX_LAST, // XGL_PROVOKING_VERTEX_CONVENTION |
| 562 | XGL_FALSE, // primitiveRestartEnable |
| 563 | 0 // primitiveRestartIndex |
| 564 | }; |
| 565 | |
| 566 | XGL_PIPELINE_RS_STATE_CREATE_INFO rs_state = { |
| 567 | XGL_STRUCTURE_TYPE_PIPELINE_RS_STATE_CREATE_INFO, |
| 568 | &ia_state, |
| 569 | XGL_FALSE, // depthClipEnable |
| 570 | XGL_FALSE, // rasterizerDiscardEnable |
| 571 | 1.0 // pointSize |
| 572 | }; |
| 573 | |
| 574 | XGL_PIPELINE_CB_STATE cb_state = { |
| 575 | XGL_STRUCTURE_TYPE_PIPELINE_CB_STATE_CREATE_INFO, |
| 576 | &rs_state, |
| 577 | XGL_FALSE, // alphaToCoverageEnable |
| 578 | XGL_FALSE, // dualSourceBlendEnable |
| 579 | XGL_LOGIC_OP_COPY, // XGL_LOGIC_OP |
| 580 | { // XGL_PIPELINE_CB_ATTACHMENT_STATE |
| 581 | { |
| 582 | XGL_FALSE, // blendEnable |
Chia-I Wu | f5d5c1a | 2014-08-27 15:02:10 +0800 | [diff] [blame] | 583 | {XGL_CH_FMT_R8G8B8A8, XGL_NUM_FMT_UNORM}, // XGL_FORMAT |
Courtney Goeltzenleuchter | ac8bd17 | 2014-08-20 15:28:00 -0600 | [diff] [blame] | 584 | 0xF // channelWriteMask |
| 585 | } |
| 586 | } |
| 587 | }; |
| 588 | |
| 589 | // TODO: Should take depth buffer format from queried formats |
| 590 | XGL_PIPELINE_DB_STATE_CREATE_INFO db_state = { |
| 591 | XGL_STRUCTURE_TYPE_PIPELINE_DB_STATE_CREATE_INFO, |
| 592 | &cb_state, |
| 593 | {XGL_CH_FMT_R32, XGL_NUM_FMT_DS} // XGL_FORMAT |
| 594 | }; |
| 595 | |
| 596 | info.sType = XGL_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; |
| 597 | info.pNext = &db_state; |
| 598 | info.flags = 0; |
Tobin Ehlis | 34e0e44 | 2014-10-07 14:41:29 -0600 | [diff] [blame^] | 599 | |
| 600 | err = xglCreateGraphicsPipeline(device(), &info, pipeline); |
Courtney Goeltzenleuchter | ac8bd17 | 2014-08-20 15:28:00 -0600 | [diff] [blame] | 601 | ASSERT_XGL_SUCCESS(err); |
Tobin Ehlis | 34e0e44 | 2014-10-07 14:41:29 -0600 | [diff] [blame^] | 602 | } |
Courtney Goeltzenleuchter | ac8bd17 | 2014-08-20 15:28:00 -0600 | [diff] [blame] | 603 | |
Tobin Ehlis | 34e0e44 | 2014-10-07 14:41:29 -0600 | [diff] [blame^] | 604 | void XglRenderTest::GenerateClearAndPrepareBufferCmds(XglImage *renderTarget) |
| 605 | { |
Courtney Goeltzenleuchter | a948d84 | 2014-08-22 16:27:58 -0600 | [diff] [blame] | 606 | // whatever we want to do, we do it to the whole buffer |
| 607 | XGL_IMAGE_SUBRESOURCE_RANGE srRange = {}; |
| 608 | srRange.aspect = XGL_IMAGE_ASPECT_COLOR; |
| 609 | srRange.baseMipLevel = 0; |
| 610 | srRange.mipLevels = XGL_LAST_MIP_OR_SLICE; |
| 611 | srRange.baseArraySlice = 0; |
| 612 | srRange.arraySize = XGL_LAST_MIP_OR_SLICE; |
| 613 | |
| 614 | // prepare the whole back buffer for clear |
| 615 | XGL_IMAGE_STATE_TRANSITION transitionToClear = {}; |
Courtney Goeltzenleuchter | 04814f8 | 2014-09-01 16:37:18 -0600 | [diff] [blame] | 616 | transitionToClear.image = renderTarget->image(); |
| 617 | transitionToClear.oldState = renderTarget->state(); |
Courtney Goeltzenleuchter | a948d84 | 2014-08-22 16:27:58 -0600 | [diff] [blame] | 618 | transitionToClear.newState = XGL_IMAGE_STATE_CLEAR; |
| 619 | transitionToClear.subresourceRange = srRange; |
| 620 | xglCmdPrepareImages( m_cmdBuffer, 1, &transitionToClear ); |
Courtney Goeltzenleuchter | 04814f8 | 2014-09-01 16:37:18 -0600 | [diff] [blame] | 621 | renderTarget->state(( XGL_IMAGE_STATE ) transitionToClear.newState); |
Courtney Goeltzenleuchter | a948d84 | 2014-08-22 16:27:58 -0600 | [diff] [blame] | 622 | |
| 623 | // clear the back buffer to dark grey |
| 624 | XGL_UINT clearColor[4] = {64, 64, 64, 0}; |
Courtney Goeltzenleuchter | 04814f8 | 2014-09-01 16:37:18 -0600 | [diff] [blame] | 625 | xglCmdClearColorImageRaw( m_cmdBuffer, renderTarget->image(), clearColor, 1, &srRange ); |
Courtney Goeltzenleuchter | a948d84 | 2014-08-22 16:27:58 -0600 | [diff] [blame] | 626 | |
| 627 | // prepare back buffer for rendering |
| 628 | XGL_IMAGE_STATE_TRANSITION transitionToRender = {}; |
Courtney Goeltzenleuchter | 04814f8 | 2014-09-01 16:37:18 -0600 | [diff] [blame] | 629 | transitionToRender.image = renderTarget->image(); |
| 630 | transitionToRender.oldState = renderTarget->state(); |
Courtney Goeltzenleuchter | a948d84 | 2014-08-22 16:27:58 -0600 | [diff] [blame] | 631 | transitionToRender.newState = XGL_IMAGE_STATE_TARGET_RENDER_ACCESS_OPTIMAL; |
| 632 | transitionToRender.subresourceRange = srRange; |
| 633 | xglCmdPrepareImages( m_cmdBuffer, 1, &transitionToRender ); |
Courtney Goeltzenleuchter | 04814f8 | 2014-09-01 16:37:18 -0600 | [diff] [blame] | 634 | renderTarget->state(( XGL_IMAGE_STATE ) transitionToClear.newState); |
Tobin Ehlis | 34e0e44 | 2014-10-07 14:41:29 -0600 | [diff] [blame^] | 635 | } |
Courtney Goeltzenleuchter | a948d84 | 2014-08-22 16:27:58 -0600 | [diff] [blame] | 636 | |
Tobin Ehlis | 34e0e44 | 2014-10-07 14:41:29 -0600 | [diff] [blame^] | 637 | void XglRenderTest::GenerateBindRenderTargetCmd(XglImage *renderTarget) |
| 638 | { |
Courtney Goeltzenleuchter | a948d84 | 2014-08-22 16:27:58 -0600 | [diff] [blame] | 639 | // bind render target |
| 640 | XGL_COLOR_ATTACHMENT_BIND_INFO colorBind = {}; |
Courtney Goeltzenleuchter | 04814f8 | 2014-09-01 16:37:18 -0600 | [diff] [blame] | 641 | colorBind.view = renderTarget->targetView(); |
Courtney Goeltzenleuchter | a948d84 | 2014-08-22 16:27:58 -0600 | [diff] [blame] | 642 | colorBind.colorAttachmentState = XGL_IMAGE_STATE_TARGET_RENDER_ACCESS_OPTIMAL; |
| 643 | xglCmdBindAttachments(m_cmdBuffer, 1, &colorBind, NULL ); |
Tobin Ehlis | 34e0e44 | 2014-10-07 14:41:29 -0600 | [diff] [blame^] | 644 | } |
Courtney Goeltzenleuchter | a948d84 | 2014-08-22 16:27:58 -0600 | [diff] [blame] | 645 | |
Tobin Ehlis | 34e0e44 | 2014-10-07 14:41:29 -0600 | [diff] [blame^] | 646 | void XglRenderTest::GenerateBindStateAndPipelineCmds(XGL_PIPELINE* pipeline) |
| 647 | { |
Courtney Goeltzenleuchter | a948d84 | 2014-08-22 16:27:58 -0600 | [diff] [blame] | 648 | // set all states |
| 649 | xglCmdBindStateObject( m_cmdBuffer, XGL_STATE_BIND_RASTER, m_stateRaster ); |
| 650 | xglCmdBindStateObject( m_cmdBuffer, XGL_STATE_BIND_VIEWPORT, m_stateViewport ); |
Courtney Goeltzenleuchter | 68cfe61 | 2014-08-26 18:16:41 -0600 | [diff] [blame] | 651 | xglCmdBindStateObject( m_cmdBuffer, XGL_STATE_BIND_COLOR_BLEND, m_colorBlend); |
Courtney Goeltzenleuchter | a948d84 | 2014-08-22 16:27:58 -0600 | [diff] [blame] | 652 | xglCmdBindStateObject( m_cmdBuffer, XGL_STATE_BIND_DEPTH_STENCIL, m_stateDepthStencil ); |
| 653 | xglCmdBindStateObject( m_cmdBuffer, XGL_STATE_BIND_MSAA, m_stateMsaa ); |
| 654 | |
| 655 | // bind pipeline, vertex buffer (descriptor set) and WVP (dynamic memory view) |
Tobin Ehlis | 34e0e44 | 2014-10-07 14:41:29 -0600 | [diff] [blame^] | 656 | xglCmdBindPipeline( m_cmdBuffer, XGL_PIPELINE_BIND_POINT_GRAPHICS, *pipeline ); |
| 657 | } |
| 658 | |
| 659 | void XglRenderTest::DrawRotatedTriangleTest() |
| 660 | { |
| 661 | // TODO : This test will pass a matrix into VS to affect triangle orientation. |
| 662 | } |
| 663 | |
| 664 | void XglRenderTest::DrawTriangleTest() |
| 665 | { |
| 666 | XGL_PIPELINE pipeline; |
| 667 | XGL_SHADER vs, ps; |
| 668 | XGL_RESULT err; |
| 669 | int width = 256, height = 256; |
| 670 | CreateDefaultPipeline(&pipeline, &vs, &ps, width, height); |
| 671 | //ASSERT_XGL_SUCCESS(err); |
| 672 | |
| 673 | err = m_device->AllocAndBindGpuMemory(pipeline, "Pipeline", &m_pipe_mem); |
| 674 | ASSERT_XGL_SUCCESS(err); |
| 675 | |
| 676 | /* |
| 677 | * Shaders are now part of the pipeline, don't need these anymore |
| 678 | */ |
| 679 | ASSERT_XGL_SUCCESS(xglDestroyObject(ps)); |
| 680 | ASSERT_XGL_SUCCESS(xglDestroyObject(vs)); |
| 681 | |
| 682 | XGL_QUERY_POOL query; |
| 683 | XGL_GPU_MEMORY query_mem; |
| 684 | ASSERT_NO_FATAL_FAILURE(CreateQueryPool(XGL_QUERY_PIPELINE_STATISTICS, 1, &query, &query_mem)); |
| 685 | |
| 686 | XglImage *renderTarget; |
| 687 | XGL_FORMAT fmt = { |
| 688 | XGL_CH_FMT_R8G8B8A8, |
| 689 | XGL_NUM_FMT_UNORM |
| 690 | }; |
| 691 | ASSERT_NO_FATAL_FAILURE(m_device->CreateImage(width, height, fmt, |
| 692 | XGL_IMAGE_USAGE_SHADER_ACCESS_WRITE_BIT | |
| 693 | XGL_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, |
| 694 | &renderTarget)); |
| 695 | |
| 696 | // Build command buffer |
| 697 | err = xglBeginCommandBuffer(m_cmdBuffer, 0); |
| 698 | ASSERT_XGL_SUCCESS(err); |
| 699 | |
| 700 | GenerateClearAndPrepareBufferCmds(renderTarget); |
| 701 | GenerateBindRenderTargetCmd(renderTarget); |
| 702 | GenerateBindStateAndPipelineCmds(&pipeline); |
| 703 | |
Courtney Goeltzenleuchter | a948d84 | 2014-08-22 16:27:58 -0600 | [diff] [blame] | 704 | // xglCmdBindDescriptorSet(m_cmdBuffer, XGL_PIPELINE_BIND_POINT_GRAPHICS, 0, m_rsrcDescSet, 0 ); |
| 705 | // xglCmdBindDynamicMemoryView( m_cmdBuffer, XGL_PIPELINE_BIND_POINT_GRAPHICS, &m_constantBufferView ); |
| 706 | |
Chia-I Wu | f070ec1 | 2014-08-30 23:58:36 +0800 | [diff] [blame] | 707 | xglCmdResetQueryPool(m_cmdBuffer, query, 0, 1); |
| 708 | xglCmdBeginQuery(m_cmdBuffer, query, 0, 0); |
| 709 | |
Courtney Goeltzenleuchter | a948d84 | 2014-08-22 16:27:58 -0600 | [diff] [blame] | 710 | // render the cube |
| 711 | xglCmdDraw( m_cmdBuffer, 0, 3, 0, 1 ); |
| 712 | |
Chia-I Wu | f070ec1 | 2014-08-30 23:58:36 +0800 | [diff] [blame] | 713 | xglCmdEndQuery(m_cmdBuffer, query, 0); |
| 714 | |
Courtney Goeltzenleuchter | a948d84 | 2014-08-22 16:27:58 -0600 | [diff] [blame] | 715 | // prepare the back buffer for present |
| 716 | // XGL_IMAGE_STATE_TRANSITION transitionToPresent = {}; |
| 717 | // transitionToPresent.image = m_image; |
| 718 | // transitionToPresent.oldState = m_image_state; |
| 719 | // transitionToPresent.newState = m_display.fullscreen ? XGL_WSI_WIN_PRESENT_SOURCE_FLIP : XGL_WSI_WIN_PRESENT_SOURCE_BLT; |
| 720 | // transitionToPresent.subresourceRange = srRange; |
| 721 | // xglCmdPrepareImages( m_cmdBuffer, 1, &transitionToPresent ); |
| 722 | // m_image_state = ( XGL_IMAGE_STATE ) transitionToPresent.newState; |
| 723 | |
| 724 | // finalize recording of the command buffer |
| 725 | err = xglEndCommandBuffer( m_cmdBuffer ); |
| 726 | ASSERT_XGL_SUCCESS( err ); |
| 727 | |
| 728 | // this command buffer only uses the vertex buffer memory |
| 729 | m_numMemRefs = 0; |
| 730 | // m_memRefs[0].flags = 0; |
| 731 | // m_memRefs[0].mem = m_vtxBufferMemory; |
| 732 | |
| 733 | // submit the command buffer to the universal queue |
| 734 | err = xglQueueSubmit( m_device->m_queue, 1, &m_cmdBuffer, m_numMemRefs, m_memRefs, NULL ); |
| 735 | ASSERT_XGL_SUCCESS( err ); |
| 736 | |
Chia-I Wu | f34ac50 | 2014-08-27 14:58:05 +0800 | [diff] [blame] | 737 | err = xglQueueWaitIdle( m_device->m_queue ); |
| 738 | ASSERT_XGL_SUCCESS( err ); |
| 739 | |
Courtney Goeltzenleuchter | 68cfe61 | 2014-08-26 18:16:41 -0600 | [diff] [blame] | 740 | // Wait for work to finish before cleaning up. |
| 741 | xglDeviceWaitIdle(m_device->device()); |
| 742 | |
Chia-I Wu | f070ec1 | 2014-08-30 23:58:36 +0800 | [diff] [blame] | 743 | XGL_PIPELINE_STATISTICS_DATA stats; |
Jon Ashburn | b8e4389 | 2014-09-25 14:36:58 -0600 | [diff] [blame] | 744 | XGL_SIZE stats_size = sizeof(stats); |
Chia-I Wu | f070ec1 | 2014-08-30 23:58:36 +0800 | [diff] [blame] | 745 | err = xglGetQueryPoolResults(query, 0, 1, &stats_size, &stats); |
| 746 | ASSERT_XGL_SUCCESS( err ); |
| 747 | ASSERT_EQ(stats_size, sizeof(stats)); |
| 748 | |
| 749 | ASSERT_EQ(stats.vsInvocations, 3); |
| 750 | ASSERT_EQ(stats.cPrimitives, 1); |
| 751 | ASSERT_EQ(stats.cInvocations, 1); |
| 752 | |
| 753 | DestroyQueryPool(query, query_mem); |
| 754 | |
Courtney Goeltzenleuchter | 04814f8 | 2014-09-01 16:37:18 -0600 | [diff] [blame] | 755 | const ::testing::TestInfo* const test_info = |
| 756 | ::testing::UnitTest::GetInstance()->current_test_info(); |
| 757 | |
Courtney Goeltzenleuchter | 2802979 | 2014-09-04 16:26:02 -0600 | [diff] [blame] | 758 | // renderTarget->WritePPM(test_info->test_case_name()); |
Courtney Goeltzenleuchter | 04814f8 | 2014-09-01 16:37:18 -0600 | [diff] [blame] | 759 | // m_screen.Display(renderTarget, m_image_mem); |
Courtney Goeltzenleuchter | 2802979 | 2014-09-04 16:26:02 -0600 | [diff] [blame] | 760 | RecordImage(renderTarget); |
Chia-I Wu | f34ac50 | 2014-08-27 14:58:05 +0800 | [diff] [blame] | 761 | |
Courtney Goeltzenleuchter | a948d84 | 2014-08-22 16:27:58 -0600 | [diff] [blame] | 762 | ASSERT_XGL_SUCCESS(xglDestroyObject(pipeline)); |
Courtney Goeltzenleuchter | 68cfe61 | 2014-08-26 18:16:41 -0600 | [diff] [blame] | 763 | ASSERT_XGL_SUCCESS(xglDestroyObject(m_cmdBuffer)); |
| 764 | ASSERT_XGL_SUCCESS(xglDestroyObject(m_stateRaster)); |
| 765 | ASSERT_XGL_SUCCESS(xglDestroyObject(m_stateViewport)); |
| 766 | ASSERT_XGL_SUCCESS(xglDestroyObject(m_stateDepthStencil)); |
| 767 | ASSERT_XGL_SUCCESS(xglDestroyObject(m_stateMsaa)); |
Courtney Goeltzenleuchter | 04814f8 | 2014-09-01 16:37:18 -0600 | [diff] [blame] | 768 | free(renderTarget); |
Courtney Goeltzenleuchter | a948d84 | 2014-08-22 16:27:58 -0600 | [diff] [blame] | 769 | } |
| 770 | |
Chia-I Wu | f34ac50 | 2014-08-27 14:58:05 +0800 | [diff] [blame] | 771 | |
Courtney Goeltzenleuchter | a948d84 | 2014-08-22 16:27:58 -0600 | [diff] [blame] | 772 | TEST_F(XglRenderTest, TestDrawTriangle) { |
| 773 | DrawTriangleTest(); |
Courtney Goeltzenleuchter | b85c581 | 2014-08-19 18:35:50 -0600 | [diff] [blame] | 774 | } |
| 775 | |
Tobin Ehlis | 34e0e44 | 2014-10-07 14:41:29 -0600 | [diff] [blame^] | 776 | TEST_F(XglRenderTest, TestDrawRotatedTriangle) { |
| 777 | DrawRotatedTriangleTest(); |
| 778 | } |
| 779 | |
Courtney Goeltzenleuchter | b85c581 | 2014-08-19 18:35:50 -0600 | [diff] [blame] | 780 | int main(int argc, char **argv) { |
Courtney Goeltzenleuchter | 2802979 | 2014-09-04 16:26:02 -0600 | [diff] [blame] | 781 | int result; |
| 782 | |
Courtney Goeltzenleuchter | b85c581 | 2014-08-19 18:35:50 -0600 | [diff] [blame] | 783 | ::testing::InitGoogleTest(&argc, argv); |
Courtney Goeltzenleuchter | 2802979 | 2014-09-04 16:26:02 -0600 | [diff] [blame] | 784 | XglTestFramework::InitArgs(&argc, argv); |
| 785 | |
| 786 | result = RUN_ALL_TESTS(); |
| 787 | |
| 788 | XglTestFramework::Finish(); |
| 789 | return result; |
Courtney Goeltzenleuchter | b85c581 | 2014-08-19 18:35:50 -0600 | [diff] [blame] | 790 | } |